|
|
|
@ -26,20 +26,24 @@ |
|
|
|
|
// See COPYRIGHT and LICENSE files for more details.
|
|
|
|
|
//++
|
|
|
|
|
|
|
|
|
|
import { Component, HostListener, Input } from '@angular/core'; |
|
|
|
|
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource'; |
|
|
|
|
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service'; |
|
|
|
|
import { WorkPackagesActivityService } from 'core-app/features/work-packages/components/wp-single-view-tabs/activity-panel/wp-activity.service'; |
|
|
|
|
import { |
|
|
|
|
ChangeDetectionStrategy, Component, HostListener, Input, |
|
|
|
|
} from '@angular/core'; |
|
|
|
|
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service'; |
|
|
|
|
import { CustomActionResource } from 'core-app/features/hal/resources/custom-action-resource'; |
|
|
|
|
import { HalEventsService } from 'core-app/features/hal/services/hal-events.service'; |
|
|
|
|
import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service'; |
|
|
|
|
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service'; |
|
|
|
|
import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset'; |
|
|
|
|
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service'; |
|
|
|
|
import { HalEventsService } from 'core-app/features/hal/services/hal-events.service'; |
|
|
|
|
import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service'; |
|
|
|
|
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service'; |
|
|
|
|
import { CustomActionResource } from 'core-app/features/hal/resources/custom-action-resource'; |
|
|
|
|
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource'; |
|
|
|
|
import { WorkPackagesActivityService } from 'core-app/features/work-packages/components/wp-single-view-tabs/activity-panel/wp-activity.service'; |
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'wp-custom-action', |
|
|
|
|
templateUrl: './wp-custom-action.component.html', |
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush, |
|
|
|
|
}) |
|
|
|
|
export class WpCustomActionComponent { |
|
|
|
|
@Input() workPackage:WorkPackageResource; |
|
|
|
@ -56,14 +60,22 @@ export class WpCustomActionComponent { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fetchAction() { |
|
|
|
|
this.halResourceService.get<CustomActionResource>(this.action.href!) |
|
|
|
|
if (this.action.href === null) return; |
|
|
|
|
|
|
|
|
|
void this.halResourceService.get<CustomActionResource>(this.action.href) |
|
|
|
|
.toPromise() |
|
|
|
|
.then((action) => { |
|
|
|
|
this.action = action; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public update() { |
|
|
|
|
public get change():ResourceChangeset<WorkPackageResource> { |
|
|
|
|
return this.halEditing.changeFor(this.workPackage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public update():void { |
|
|
|
|
if (this.action.href === null) return; |
|
|
|
|
|
|
|
|
|
const payload = { |
|
|
|
|
lockVersion: this.workPackage.lockVersion, |
|
|
|
|
_links: { |
|
|
|
@ -73,6 +85,9 @@ export class WpCustomActionComponent { |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Mark changeset as in flight
|
|
|
|
|
this.change.inFlight = true; |
|
|
|
|
|
|
|
|
|
this.halResourceService |
|
|
|
|
.post<WorkPackageResource>(`${this.action.href}/execute`, payload) |
|
|
|
|
.subscribe( |
|
|
|
@ -82,16 +97,20 @@ export class WpCustomActionComponent { |
|
|
|
|
this.wpActivity.clear(this.workPackage.id); |
|
|
|
|
// Loading the schema might be necessary in cases where the button switches
|
|
|
|
|
// project or type.
|
|
|
|
|
this.apiV3Service.work_packages.cache.updateWorkPackage(savedWp).then(() => { |
|
|
|
|
void this.apiV3Service.work_packages.cache.updateWorkPackage(savedWp).then(() => { |
|
|
|
|
this.halEditing.stopEditing(savedWp); |
|
|
|
|
this.halEvents.push(savedWp, { eventType: 'updated' }); |
|
|
|
|
this.change.inFlight = false; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
(errorResource:any) => this.notificationService.handleRawError(errorResource, this.workPackage), |
|
|
|
|
(errorResource) => { |
|
|
|
|
this.notificationService.handleRawError(errorResource, this.workPackage); |
|
|
|
|
this.change.inFlight = false; |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@HostListener('mouseenter') onMouseEnter() { |
|
|
|
|
@HostListener('mouseenter') onMouseEnter():void { |
|
|
|
|
this.fetchAction(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|