Load status when entering work package

pull/6804/head
Oliver Günther 6 years ago
parent 3ba6913960
commit ef4273f79e
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 4
      frontend/src/app/components/states.service.ts
  2. 8
      frontend/src/app/components/states/state-cache.service.ts
  3. 23
      frontend/src/app/components/wp-buttons/wp-status-button/wp-status-button.component.ts
  4. 39
      frontend/src/app/modules/hal/resources/status-resource.ts
  5. 5
      frontend/src/app/modules/hal/services/hal-resource.config.ts

@ -13,6 +13,7 @@ import {QueryColumn} from './wp-query/query-column';
import {WikiPageResource} from 'core-app/modules/hal/resources/wiki-page-resource';
import {PostResource} from 'core-app/modules/hal/resources/post-resource';
import {HalResource} from 'core-app/modules/hal/resources/hal-resource';
import {StatusResource} from "core-app/modules/hal/resources/status-resource";
export class States extends StatesGroup {
[key:string]:any;
@ -37,6 +38,9 @@ export class States extends StatesGroup {
/* /api/v3/types */
types = multiInput<TypeResource>();
/* /api/v3/types */
statuses = multiInput<StatusResource>();
/* /api/v3/users */
users = multiInput<UserResource>();

@ -27,6 +27,7 @@
// ++
import {InputState, MultiInputState, State} from 'reactivestates';
import {Observable} from "rxjs";
export abstract class StateCacheService<T> {
private cacheDurationInMs:number;
@ -57,6 +58,13 @@ export abstract class StateCacheService<T> {
this.multiState.get(id).putValue(val);
}
/**
* Observe the value of the given id
*/
public observe(id:string):Observable<T> {
return this.state(id).values$();
}
/**
* Clear a set of cached states.
* @param ids

@ -28,17 +28,19 @@
import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
import {WorkPackageEditingService} from 'core-components/wp-edit-form/work-package-editing-service';
import {Component, Inject, Input} from '@angular/core';
import {Component, Inject, Input, OnDestroy, OnInit} from '@angular/core';
import {I18nService} from 'core-app/modules/common/i18n/i18n.service';
import {IWorkPackageEditingServiceToken} from "../../wp-edit-form/work-package-editing.service.interface";
import {Highlighting} from "core-components/wp-fast-table/builders/highlighting/highlighting.functions";
import {HalResource} from "core-app/modules/hal/resources/hal-resource";
import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";
import {untilComponentDestroyed} from "ng2-rx-componentdestroyed";
@Component({
selector: 'wp-status-button',
templateUrl: './wp-status-button.html'
})
export class WorkPackageStatusButtonComponent {
export class WorkPackageStatusButtonComponent implements OnInit, OnDestroy {
@Input('workPackage') public workPackage:WorkPackageResource;
public text = {
@ -47,9 +49,26 @@ export class WorkPackageStatusButtonComponent {
};
constructor(readonly I18n:I18nService,
readonly wpCacheService:WorkPackageCacheService,
@Inject(IWorkPackageEditingServiceToken) protected wpEditing:WorkPackageEditingService) {
}
ngOnInit() {
this.wpCacheService
.observe(this.workPackage.id)
.pipe(
untilComponentDestroyed(this)
)
.subscribe((wp) => {
this.workPackage = wp;
this.workPackage.status.$load();
});
}
ngOnDestroy():void {
// Nothing to do
}
public isDisabled() {
let changeset = this.wpEditing.changesetFor(this.workPackage);
return !this.allowed || changeset.inFlight;

@ -0,0 +1,39 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 3.
//
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
// Copyright (C) 2006-2013 Jean-Philippe Lang
// Copyright (C) 2010-2013 the ChiliProject Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
//++
import {HalResource} from 'core-app/modules/hal/resources/hal-resource';
import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';
import {InputState} from 'reactivestates';
export class StatusResource extends HalResource {
public get state():InputState<this> {
return this.states.statuses.get(this.href as string) as any;
}
}

@ -52,6 +52,7 @@ import {Injectable} from '@angular/core';
import {HalResource} from 'core-app/modules/hal/resources/hal-resource';
import {WikiPageResource} from "core-app/modules/hal/resources/wiki-page-resource";
import {PostResource} from "core-app/modules/hal/resources/post-resource";
import {StatusResource} from "core-app/modules/hal/resources/status-resource";
const halResourceDefaultConfig:{ [typeName:string]:HalResourceFactoryConfigInterface } = {
WorkPackage: {
@ -62,6 +63,7 @@ const halResourceDefaultConfig:{ [typeName:string]:HalResourceFactoryConfigInter
children: 'WorkPackage',
relations: 'Relation',
schema: 'Schema',
status: 'Status',
type: 'Type'
}
},
@ -96,6 +98,9 @@ const halResourceDefaultConfig:{ [typeName:string]:HalResourceFactoryConfigInter
Type: {
cls: TypeResource
},
Status: {
cls: StatusResource
},
SchemaDependency: {
cls: SchemaDependencyResource
},

Loading…
Cancel
Save