deduce view to create from current uistate

pull/9957/head
ulferts 3 years ago committed by Henriette Darge
parent 244951aa5b
commit aad2bac1ac
  1. 10
      frontend/src/app/core/apiv3/endpoints/views/apiv3-views-paths.ts
  2. 13
      frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts
  3. 41
      frontend/src/app/features/work-packages/components/wp-list/wp-query-view.service.ts
  4. 3
      frontend/src/app/features/work-packages/openproject-work-packages.module.ts

@ -34,17 +34,17 @@ import { ViewResource } from 'core-app/features/hal/resources/views-resource';
export class APIv3ViewsPaths extends APIv3ResourceCollection<ViewResource, APIv3GettableResource<ViewResource>> {
constructor(protected apiRoot:APIV3Service,
protected basePath:string) {
super(apiRoot, basePath, 'views/work_packages_table');
super(apiRoot, basePath, 'views');
}
/**
* Create a new query resource
* Create a new view resource
*
* @param payload Payload object or query HAL resource
* @param payload Payload object or view HAL resource
*/
public post(resource:ViewResource|Object):Observable<ViewResource> {
public post(resource:ViewResource|unknown, type:string):Observable<ViewResource> {
return this
.halResourceService
.post<ViewResource>(this.path, resource);
.post<ViewResource>(`${this.path}/${type}`, resource);
}
}

@ -52,6 +52,7 @@ import { ErrorResource } from 'core-app/features/hal/resources/error-resource';
import { QueryFormResource } from 'core-app/features/hal/resources/query-form-resource';
import { WorkPackageStatesInitializationService } from './wp-states-initialization.service';
import { WorkPackagesListInvalidQueryService } from './wp-list-invalid-query.service';
import { WorkPackagesQueryViewService } from 'core-app/features/work-packages/components/wp-list/wp-query-view.service';
export interface QueryDefinition {
queryParams:{ query_id?:string, query_props?:string };
@ -98,6 +99,7 @@ export class WorkPackagesListService {
protected wpTablePagination:WorkPackageViewPaginationService,
protected wpStatesInitialization:WorkPackageStatesInitializationService,
protected wpListInvalidQueryService:WorkPackagesListInvalidQueryService,
protected wpQueryView:WorkPackagesQueryViewService,
) { }
/**
@ -388,15 +390,8 @@ export class WorkPackagesListService {
.post(query, form)
.pipe(
switchMap((createdQuery) => this
.apiV3Service
.views
.post({
_links: {
query: {
href: createdQuery.href,
},
},
})
.wpQueryView
.create(createdQuery)
.pipe(
mapTo(createdQuery),
)),

@ -0,0 +1,41 @@
import { Injectable } from '@angular/core';
import { StateService } from '@uirouter/core';
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';
import { ViewResource } from 'core-app/features/hal/resources/views-resource';
import { Observable } from 'rxjs';
@Injectable()
export class WorkPackagesQueryViewService {
constructor(
protected $state:StateService,
protected apiV3Service:APIV3Service,
) { }
create(query:QueryResource):Observable<ViewResource> {
return this
.apiV3Service
.views
.post(
{
_links: {
query: {
href: query.href,
},
},
},
this.viewType,
);
}
private get viewType() {
if (this.$state.includes('work-packages')) {
return 'work_packages_table';
}
if (this.$state.includes('team_planner')) {
return 'team_planner';
}
throw new Error('Not on a path defined for query views');
}
}

@ -171,6 +171,7 @@ import { WorkPackageFilterContainerComponent } from 'core-app/features/work-pack
import { FilterBooleanValueComponent } from 'core-app/features/work-packages/components/filters/filter-boolean-value/filter-boolean-value.component';
import { WorkPackageMarkNotificationButtonComponent } from 'core-app/features/work-packages/components/wp-buttons/wp-mark-notification-button/work-package-mark-notification-button.component';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
import { WorkPackagesQueryViewService } from 'core-app/features/work-packages/components/wp-list/wp-query-view.service';
@NgModule({
imports: [
@ -221,6 +222,8 @@ import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
WorkPackageRelationsService,
WorkPackageWatchersService,
WorkPackagesQueryViewService,
HalEventsService,
],
declarations: [

Loading…
Cancel
Save