OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add subproject boards and extract common board action class
Oliver Güntherd43d9e6e00ec
diff --git a/app/models/queries/work_packages.rb b/app/models/queries/work_packages.rbindex 65f9981afa1..5dc430fd2d5 100644--- a/app/models/queries/work_packages.rb+++ b/app/models/queries/work_packages.rb@@ -53,6 +53,7 @@ module Queries::WorkPackagesregister.filter Query, filters_module::StatusFilterregister.filter Query, filters_module::SubjectFilterregister.filter Query, filters_module::SubprojectFilter+ register.filter Query, filters_module::OnlySubprojectFilterregister.filter Query, filters_module::TypeFilterregister.filter Query, filters_module::UpdatedAtFilterregister.filter Query, filters_module::VersionFilterdiff --git a/app/models/queries/work_packages/filter/only_subproject_filter.rb b/app/models/queries/work_packages/filter/only_subproject_filter.rbnew file mode 100644index 00000000000..99b4293aee1--- /dev/null+++ b/app/models/queries/work_packages/filter/only_subproject_filter.rb@@ -0,0 +1,47 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++class Queries::WorkPackages::Filter::OnlySubprojectFilter <+ Queries::WorkPackages::Filter::SubprojectFilter++ def human_name+ I18n.t('query_fields.only_subproject_id')+ end++ def self.key+ :only_subproject_id+ end++ private++ def ids_for_where+ ids_for_where_subproject+ end+enddiff --git a/app/models/queries/work_packages/filter/subproject_filter.rb b/app/models/queries/work_packages/filter/subproject_filter.rbindex 2e1efcd62c7..fac308b54b5 100644--- a/app/models/queries/work_packages/filter/subproject_filter.rb+++ b/app/models/queries/work_packages/filter/subproject_filter.rb@@ -76,20 +76,24 @@ class Queries::WorkPackages::Filter::SubprojectFilter <"#{Project.table_name}.id IN (%s)" % ids_for_where.join(',')end- private+ protecteddef ids_for_where- [project.id] + case operator- when ::Queries::Operators::Equals.symbol- # include the selected subprojects- value_ints- when ::Queries::Operators::All.symbol- visible_subproject_ids- when ::Queries::Operators::NotEquals.symbol- visible_subproject_ids - value_ints- else # None- []- end+ [project.id] + ids_for_where_subproject+ end++ def ids_for_where_subproject+ case operator+ when ::Queries::Operators::Equals.symbol+ # include the selected subprojects+ value_ints+ when ::Queries::Operators::All.symbol+ visible_subproject_ids+ when ::Queries::Operators::NotEquals.symbol+ visible_subproject_ids - value_ints+ else # None+ []+ endenddef visible_subproject_arraydiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 3193cf8ad49..f3d2a0c0812 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2056,7 +2056,8 @@ en:assigned_to_role: "Assignee's role"member_of_group: "Assignee's group"assignee_or_group: "Assignee or belonging group"- subproject_id: "Subproject"+ subproject_id: "Including Subproject"+ only_subproject_id: "Only subproject"name_or_identifier: "Name or identifier"repositories:diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 6ae50e5b9f8..79d19964979 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -818,6 +818,7 @@ en:startDate: "Start date"status: "Status"subject: "Subject"+ subproject: "Subproject"title: "Title"type: "Type"updatedAt: "Updated on"diff --git a/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.tsindex 27c77dfb3ad..a95ce8706d4 100644--- a/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts@@ -1,134 +1,24 @@-import {Injectable, Injector} from "@angular/core";-import {BoardListsService} from "core-app/modules/boards/board/board-list/board-lists.service";-import {Board} from "core-app/modules/boards/board/board";-import {QueryResource} from "core-app/modules/hal/resources/query-resource";+import {Injectable} from "@angular/core";import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {I18nService} from "core-app/modules/common/i18n/i18n.service";-import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";-import {CreateAutocompleterComponent} from "core-app/modules/common/autocomplete/create-autocompleter.component";-import {OpContextMenuItem} from "core-components/op-context-menu/op-context-menu.types";import {UserResource} from 'core-app/modules/hal/resources/user-resource';-import {CurrentProjectService} from 'core-app/components/projects/current-project.service';import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';-import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';import {AssigneeBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/assignee/assignee-board-header.component";-import {input} from "reactivestates";-import {take} from "rxjs/operators";-import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";-import {InjectField} from "core-app/helpers/angular/inject-field.decorator";import {ProjectResource} from "core-app/modules/hal/resources/project-resource";-import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";-import {APIv3GettableResource} from "core-app/modules/apiv3/paths/apiv3-resource";+import {take} from "rxjs/operators";@Injectable()-export class BoardAssigneeActionService implements BoardActionService {-- private assignees = input<HalResource[]>();--- constructor(protected boardListsService:BoardListsService,- protected I18n:I18nService,- protected halResourceService:HalResourceService,- protected pathHelper:PathHelperService,- protected apiV3Service:APIV3Service,- protected currentProject:CurrentProjectService,- readonly injector:Injector) {- }+export class BoardAssigneeActionService extends BoardActionService {+ filterName = 'assignee';public get localizedName() {return this.I18n.t('js.work_packages.properties.assignee');}- /**- * Returns the current filter value if any- * @param query- * @returns /api/v3/assignee/:id if a assignee filter exists- */- public getFilterHref(query:QueryResource):string|undefined {- const filter = _.find(query.filters, filter => filter.id === 'assignee');- if (filter) {- const value = filter.values[0] as string|HalResource;- return (value instanceof HalResource) ? value.href! : value;- }-- return;- }-- /**- * Returns the loaded assignee- * @param query- */- public getLoadedFilterValue(query:QueryResource):Promise<undefined|HalResource> {- const href = this.getFilterHref(query);-- if (!href) {- return Promise.resolve(undefined);- }-- return this- .getAssignees()- .then(collection => collection.find(resource => resource.href === href));- }-- public canAddToQuery(query:QueryResource):Promise<boolean> {- return Promise.resolve(true);- }-- public addActionQueries(board:Board):Promise<Board> {- return Promise.resolve(board);- }-- public addActionQuery(board:Board, value:HalResource):Promise<Board> {- let params:any = {- name: value.name,- };-- let filter = {- assignee: {- operator: '=' as FilterOperator,- values: [value.id]- }- };-- return this.boardListsService.addQuery(board, params, [filter]);- }-- /**- * Return available assignees for new lists, given the list of active- * queries in the board.- *- * @param board The board we're looking at- * @param active The active set of values (hrefs)- */- public getAvailableValues(board:Board, active:Set<string>):Promise<HalResource[]> {- return this- .getAssignees()- .then(results =>- results.filter(assignee => !active.has(assignee.id!))- );- }-- public getAdditionalListMenuItems(query:QueryResource):Promise<OpContextMenuItem[]> {- return Promise.resolve([]);- }-- dragIntoAllowed(query:QueryResource, value:HalResource|undefined) {- return true;- }-- public autocompleterComponent() {- return CreateAutocompleterComponent;- }-public headerComponent() {return AssigneeBoardHeaderComponent;}- public disabledAddButtonPlaceholder(assignee:HalResource) {- return undefined;- }-public warningTextWhenNoOptionsAvailable() {let text = this.I18n.t('js.boards.add_list_modal.warning.assignee');@@ -151,22 +41,14 @@ export class BoardAssigneeActionService implements BoardActionService {});}- private getAssignees():Promise<HalResource[]> {- this.assignees.putFromPromiseIfPristine(() =>- this- .apiV3Service- .projects- .id(this.currentProject.identifier!)- .available_assignees- .get()- .toPromise()- .then((collection:CollectionResource<UserResource>) => collection.elements)- );-- return this.assignees- .values$()- .pipe(take(1))- .toPromise();+ protected loadAvailable():Promise<HalResource[]> {+ return this+ .apiV3Service+ .projects+ .id(this.currentProject.identifier!)+ .available_assignees+ .get()+ .toPromise()+ .then((collection:CollectionResource<UserResource>) => collection.elements);}-}diff --git a/frontend/src/app/modules/boards/board/board-actions/board-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/board-action.service.tsindex 630d7ce218d..598f3deed90 100644--- a/frontend/src/app/modules/boards/board/board-actions/board-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/board-action.service.ts@@ -4,39 +4,106 @@ import {HalResource} from "core-app/modules/hal/resources/hal-resource";import {ComponentType} from "@angular/cdk/portal";import {OpContextMenuItem} from "core-components/op-context-menu/op-context-menu.types";import {DisabledButtonPlaceholder} from "core-app/modules/boards/board/board-list/board-list.component";+import {CreateAutocompleterComponent} from "core-app/modules/common/autocomplete/create-autocompleter.component";+import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";+import {BoardListsService} from "core-app/modules/boards/board/board-list/board-lists.service";+import {I18nService} from "core-app/modules/common/i18n/i18n.service";+import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";+import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";+import {CurrentProjectService} from "core-components/projects/current-project.service";+import {Injectable, Injector} from "@angular/core";+import {take} from "rxjs/operators";+import {input} from "reactivestates";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {IFieldSchema} from "core-app/modules/fields/field.base";+import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changeset";+import {WorkPackageFilterValues} from "core-components/wp-edit-form/work-package-filter-values";+import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";++@Injectable()+export abstract class BoardActionService {++ // Cache the available values for the duration of the board+ protected cache = input<HalResource[]>();++ constructor(readonly injector:Injector,+ protected boardListsService:BoardListsService,+ protected I18n:I18nService,+ protected halResourceService:HalResourceService,+ protected pathHelper:PathHelperService,+ protected currentProject:CurrentProjectService,+ protected apiV3Service:APIV3Service) {+ }-export interface BoardActionService {/*** Get the attribute name*/localizedName:string;+ /**+ * The action filter name+ */+ filterName:string;+/*** Returns the current filter value ID if any* @param query* @returns /api/v3/status/:id if a status filter exists*/- getFilterHref(query:QueryResource):string|undefined;+ getFilterHref(query:QueryResource):string|undefined {+ const filter = _.find(query.filters, filter => filter.id === this.filterName);+ if (filter) {+ const value = filter.values[0] as string|HalResource;+ return (value instanceof HalResource) ? value.href! : value;+ }++ return;+ }/*** Returns the current filter value if any* @param query* @returns /api/v3/status/:id if a status filter exists*/- getLoadedFilterValue(query:QueryResource):Promise<HalResource|undefined>;+ getLoadedFilterValue(query:QueryResource):Promise<HalResource|undefined> {+ const href = this.getFilterHref(query);++ if (!href) {+ return Promise.resolve(undefined);+ }++ return this+ .withLoadedAvailable()+ .then(collection => collection.find(resource => resource.href === href));+ }/*** Add initial queries to a new board** @param newBoard*/- addActionQueries(newBoard:Board):Promise<Board>;+ addActionQueries(newBoard:Board):Promise<Board> {+ return Promise.resolve(newBoard);+ }/*** Add a single action query*/- addActionQuery(board:Board, value:HalResource):Promise<Board>;+ addActionQuery(board:Board, value:HalResource):Promise<Board> {+ let params:any = {+ name: value.name,+ };++ let filter = {+ [this.filterName]: {+ operator: '=' as FilterOperator,+ values: [value.idFromLink]+ }+ };++ return this.boardListsService.addQuery(board, params, [filter]);+ }/*** Get available values from the active queries@@ -44,13 +111,53 @@ export interface BoardActionService {* @param board The board we're looking at* @param active The active set of values (hrefs or plain values)*/- getAvailableValues(board:Board, active:Set<string>):Promise<HalResource[]>;+ getAvailableValues(board:Board, active:Set<string>):Promise<HalResource[]> {+ return this+ .withLoadedAvailable()+ .then(results =>+ results.filter(item => !active.has(item.id!))+ );+ }/*** Get action specific items that shall be shown in the list menu* @returns {any[]}*/- getAdditionalListMenuItems(query:QueryResource):Promise<OpContextMenuItem[]>;+ getAdditionalListMenuItems(query:QueryResource):Promise<OpContextMenuItem[]> {+ return Promise.resolve([]);+ }++ /**+ * Get the specific component for the autocompleter (e.g versionAutocompleter)+ * @returns {Component}+ */+ autocompleterComponent():ComponentType<unknown> {+ return CreateAutocompleterComponent;+ }++ /**+ * Get the specific header component for the board list, or undefined if none+ * @returns {Component}+ */+ headerComponent():ComponentType<unknown>|undefined {+ return undefined;+ }++ /**+ * Get icon and text to show on the add button when it is disabled+ * @returns {the icon class or nothing}+ */+ disabledAddButtonPlaceholder(resource?:HalResource):DisabledButtonPlaceholder|undefined {+ return undefined;+ }++ /**+ * Determines the specific warning to be shown, when there are no options to add as a list+ * @returns {the text or nothing}+ */+ warningTextWhenNoOptionsAvailable():Promise<string|undefined> {+ return Promise.resolve(undefined);+ }/*** Determine whether we can drag items into a given query for the@@ -59,35 +166,52 @@ export interface BoardActionService {* @param query* @param value*/- dragIntoAllowed(query:QueryResource, value:HalResource|undefined):boolean;+ dragIntoAllowed(query:QueryResource, value:HalResource|undefined):boolean {+ return true;+ }/*** Determine whether we can create new items for this action attribute*/- canAddToQuery(query:QueryResource):Promise<boolean>;-+ canAddToQuery(query:QueryResource):Promise<boolean> {+ return Promise.resolve(true);+ }/**- * Get the specific component for the autocompleter (e.g versionAutocompleter)- * @returns {Component}+ * Determine whether the given work package can be moved*/- autocompleterComponent():ComponentType<unknown>;+ canMove(workPackage:WorkPackageResource):boolean {+ const fieldSchema = workPackage.schema[this.filterName] as IFieldSchema;+ return fieldSchema?.writable;+ }/**- * Get the specific header component for the board list, or undefined if none- * @returns {Component}+ * Assign the work package to the action attribute*/- headerComponent():ComponentType<unknown>|undefined;+ assignToWorkPackage(changeset:WorkPackageChangeset, query:QueryResource) {+ // Ensure attribute remains writable in the form+ if (!changeset.isWritable(this.filterName)) {+ throw this.I18n.t(+ 'js.boards.error_attribute_not_writable',+ { attribute: changeset.humanName(this.filterName) }+ );+ }- /**- * Get icon and text to show on the add button when it is disabled- * @returns {the icon class or nothing}- */- disabledAddButtonPlaceholder(resource?:HalResource):DisabledButtonPlaceholder|undefined;+ const filter = new WorkPackageFilterValues(this.injector, changeset, query.filters);+ filter.applyDefaultsFromFilters();+ }++ protected withLoadedAvailable():Promise<HalResource[]> {+ this.cache.putFromPromiseIfPristine(() => this.loadAvailable());++ return this.cache+ .values$()+ .pipe(take(1))+ .toPromise();+ }/**- * Determines the specific warning to be shown, when there are no options to add as a list- * @returns {the text or nothing}+ * Load the available values for this action attribute*/- warningTextWhenNoOptionsAvailable():Promise<string|undefined>;+ protected abstract loadAvailable():Promise<HalResource[]>;}diff --git a/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.tsindex b47857c1ba2..93452498d05 100644--- a/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/status/status-action.service.ts@@ -1,69 +1,18 @@import {Injectable} from "@angular/core";-import {BoardListsService} from "core-app/modules/boards/board/board-list/board-lists.service";import {Board} from "core-app/modules/boards/board/board";import {StatusResource} from "core-app/modules/hal/resources/status-resource";-import {QueryResource} from "core-app/modules/hal/resources/query-resource";import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";-import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {I18nService} from "core-app/modules/common/i18n/i18n.service";-import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";-import {CreateAutocompleterComponent} from "core-app/modules/common/autocomplete/create-autocompleter.component";-import {OpContextMenuItem} from "core-components/op-context-menu/op-context-menu.types";-import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Injectable()-export class BoardStatusActionService implements BoardActionService {-- constructor(protected boardListsService:BoardListsService,- protected I18n:I18nService,- protected apiV3Service:APIV3Service) {- }+export class BoardStatusActionService extends BoardActionService {+ filterName = 'status';public get localizedName() {return this.I18n.t('js.work_packages.properties.status');}- /**- * Returns the current filter value if any- * @param query- * @returns /api/v3/status/:id if a status filter exists- */- public getFilterHref(query:QueryResource):string|undefined {- const filter = _.find(query.filters, filter => filter.id === 'status');-- if (filter) {- const value = filter.values[0] as string|HalResource;- return (value instanceof HalResource) ? value.href! : value;- }-- return;- }-- /**- * Returns the loaded status- * @param query- */- public getLoadedFilterValue(query:QueryResource):Promise<undefined|StatusResource> {- const href = this.getFilterHref(query);-- if (href) {- const id = HalResource.idFromLink(href);- return this- .apiV3Service- .statuses.id(id)- .get()- .toPromise();- } else {- return Promise.resolve(undefined);- }- }-- public canAddToQuery(query:QueryResource):Promise<boolean> {- return Promise.resolve(true);- }-public addActionQueries(board:Board):Promise<Board> {- return this.getStatuses()+ return this.withLoadedAvailable().then((results) =>Promise.all<unknown>(results.map((status:StatusResource) => {@@ -79,60 +28,11 @@ export class BoardStatusActionService implements BoardActionService {);}- public addActionQuery(board:Board, value:HalResource):Promise<Board> {- let params:any = {- name: value.name,- };-- let filter = {- status: {- operator: '=' as FilterOperator,- values: [value.id]- }- };-- return this.boardListsService.addQuery(board, params, [filter]);- }-- /**- * Return available statuses for new lists, given the list of active- * queries in the board.- *- * @param board The board we're looking at- * @param active The active set of values (hrefs or plain values)- */- public getAvailableValues(board:Board, active:Set<string>):Promise<HalResource[]> {- return this.getStatuses()- .then(results =>- results.filter(status => !active.has(status.id!))- );- }-- public getAdditionalListMenuItems(query:QueryResource):Promise<OpContextMenuItem[]> {- return Promise.resolve([]);- }-- dragIntoAllowed(query:QueryResource, value:HalResource|undefined) {- return true;- }-- public autocompleterComponent() {- return CreateAutocompleterComponent;- }-- public headerComponent() {- return undefined;- }-- public disabledAddButtonPlaceholder(status:StatusResource) {- return undefined;- }-public warningTextWhenNoOptionsAvailable() {return Promise.resolve(this.I18n.t('js.boards.add_list_modal.warning.status'));}- private getStatuses():Promise<StatusResource[]> {+ protected loadAvailable():Promise<StatusResource[]> {return this.apiV3Service.statusesdiff --git a/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-action.service.tsindex e69de29bb2d..1618142b3b5 100644--- a/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-action.service.ts@@ -0,0 +1,57 @@+import {Injectable} from "@angular/core";+import {QueryResource} from "core-app/modules/hal/resources/query-resource";+import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {buildApiV3Filter} from "core-components/api/api-v3/api-v3-filter-builder";+import {UserResource} from 'core-app/modules/hal/resources/user-resource';+import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';+import {input} from "reactivestates";+import {take} from "rxjs/operators";+import {WorkPackageChangeset} from "core-components/wp-edit/work-package-changeset";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {SubprojectBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/subproject/subproject-board-header.component";++@Injectable()+export class BoardSubprojectActionService extends BoardActionService {+ filterName = 'onlySubproject';++ private subprojects = input<HalResource[]>();++ get localizedName() {+ return this.I18n.t('js.work_packages.properties.subproject');+ }++ headerComponent() {+ return SubprojectBoardHeaderComponent;+ }++ // TODO need permission for user on subproject+ canMove(workPackage:WorkPackageResource):boolean {+ return true;+ }++ // TODO assign subproject to changeset+ assignToWorkPackage(changeset:WorkPackageChangeset, query:QueryResource) {+ const href = this.getFilterHref(query);+ changeset.setValue('project', { href: href });+ }++ protected loadAvailable():Promise<HalResource[]> {+ const currentProjectId = this.currentProject.id!;+ this.subprojects.putFromPromiseIfPristine(() =>+ this+ .apiV3Service+ .projects+ .filtered(buildApiV3Filter('ancestor', '=', currentProjectId))+ .get()+ .toPromise()+ .then((collection:CollectionResource<UserResource>) => collection.elements)+ );++ return this.subprojects+ .values$()+ .pipe(take(1))+ .toPromise();+ }++}diff --git a/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-board-header.component.ts b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-board-header.component.tsnew file mode 100644index 00000000000..3600b934610--- /dev/null+++ b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-board-header.component.ts@@ -0,0 +1,49 @@+//-- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2020 the OpenProject GmbH+//+// 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 docs/COPYRIGHT.rdoc for more details.+//+++import {Component, Input} from "@angular/core";+import {HalResource} from "core-app/modules/hal/resources/hal-resource";+import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";+import {I18nService} from "core-app/modules/common/i18n/i18n.service";+++@Component({+ templateUrl: './subproject-board-header.html',+ styleUrls: ['./subproject-board-header.sass'],+ host: { 'class': 'title-container -small' }+})+export class SubprojectBoardHeaderComponent {+ @Input() public resource:HalResource;++ text = {+ project: this.I18n.t('js.time_entry.project')+ };++ constructor(readonly pathHelper:PathHelperService,+ readonly I18n:I18nService) {+ }+}diff --git a/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-board-header.html b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-board-header.htmlnew file mode 100644index 00000000000..7da2dad3502--- /dev/null+++ b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-board-header.html@@ -0,0 +1,10 @@+<div class="subproject-board-header" *ngIf="resource">+ <h2 class="editable-toolbar-title--fixed">+ <small [textContent]="text.project"></small>+ <br/>+ <a [href]="pathHelper.projectPath(resource.idFromLink)"+ [textContent]="resource.name"+ target="_blank">+ </a>+ </h2>+</div>diff --git a/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-board-header.sass b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-board-header.sassnew file mode 100644index 00000000000..f48f5f33960--- /dev/null+++ b/frontend/src/app/modules/boards/board/board-actions/subproject/subproject-board-header.sass@@ -0,0 +1,4 @@+// Override line-height for proper+// display of the h2 + small+.editable-toolbar-title--fixed+ line-height: 1 !important\ No newline at end of filediff --git a/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.tsindex eccd9501f7e..5f556e87f78 100644--- a/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.ts+++ b/frontend/src/app/modules/boards/board/board-actions/version/version-action.service.ts@@ -1,14 +1,9 @@import {Injectable} from "@angular/core";-import {BoardListsService} from "core-app/modules/boards/board/board-list/board-lists.service";import {Board} from "core-app/modules/boards/board/board";import {QueryResource} from "core-app/modules/hal/resources/query-resource";import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";import {HalResource} from "core-app/modules/hal/resources/hal-resource";-import {I18nService} from "core-app/modules/common/i18n/i18n.service";-import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";import {VersionResource} from "core-app/modules/hal/resources/version-resource";-import {CurrentProjectService} from "core-components/projects/current-project.service";-import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {VersionAutocompleterComponent} from "core-app/modules/common/autocomplete/version-autocompleter.component";import {OpContextMenuItem} from "core-components/op-context-menu/op-context-menu.types";import {LinkHandling} from "core-app/modules/common/link-handling/link-handling";@@ -16,61 +11,21 @@ import {StateService} from "@uirouter/core";import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {VersionBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/version/version-board-header.component";import {FormResource} from "core-app/modules/hal/resources/form-resource";-import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";-import {BehaviorSubject} from "rxjs";+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";@Injectable()-export class BoardVersionActionService implements BoardActionService {+export class BoardVersionActionService extends BoardActionService {+ @InjectField() state:StateService;+ @InjectField() halNotification:HalResourceNotificationService;- private writable$:Promise<boolean>;+ filterName = 'version';- constructor(protected boardListsService:BoardListsService,- protected I18n:I18nService,- protected apiv3Service:APIV3Service,- protected currentProject:CurrentProjectService,- protected halNotification:HalResourceNotificationService,- protected state:StateService,- protected pathHelper:PathHelperService) {- }+ private writable$:Promise<boolean>;public get localizedName() {return this.I18n.t('js.work_packages.properties.version');}- /**- * Returns the current filter value if any- * @param query- * @returns /api/v3/versions/:id if a version filter exists- */- public getFilterHref(query:QueryResource):string|undefined {- const filter = _.find(query.filters, filter => filter.id === 'version');-- if (filter) {- const value = filter.values[0] as string|HalResource;- return (value instanceof HalResource) ? value.href! : value;- }-- return;- }-- /**- * Returns the loaded status- * @param query- */- public getLoadedFilterValue(query:QueryResource):Promise<undefined|VersionResource> {- const href = this.getFilterHref(query);-- if (href) {- const id = HalResource.idFromLink(href);- return this- .apiv3Service- .versions.id(id)- .get().toPromise();- } else {- return Promise.resolve(undefined);- }- }-public canAddToQuery(query:QueryResource):Promise<boolean> {const formLink = _.get(query, 'results.createWorkPackage.href', null);@@ -87,7 +42,7 @@ export class BoardVersionActionService implements BoardActionService {}public addActionQueries(board:Board):Promise<Board> {- return this.getVersions()+ return this.withLoadedAvailable().then((results) => {return Promise.all<unknown>(results.map((version:VersionResource) => {@@ -103,44 +58,15 @@ export class BoardVersionActionService implements BoardActionService {});}- public addActionQuery(board:Board, value:HalResource):Promise<Board> {- let params:any = {- name: value.name,- };-- let filter = {- version: {- operator: '=' as FilterOperator,- values: [value.id]- }- };-- return this.boardListsService.addQuery(board, params, [filter]);- }-- /**- * Return available versions for new lists, given the list of active- * queries in the board.- *- * @param board The board we're looking at- * @param active The active set of values (hrefs or plain values)- */- public getAvailableValues(board:Board, active:Set<string>):Promise<HalResource[]> {- return this.getVersions()- .then(results =>- results.filter(version => !active.has(version.id!))- );- }-/*** Adds an entry to the list menu to edit the version if allowed- * @param {QueryResource} active query+ * @param {QueryResource} query The active query* @returns {Promise<any>}*/public getAdditionalListMenuItems(query:QueryResource):Promise<OpContextMenuItem[]> {return this.getLoadedFilterValue(query)- .then(version => {+ .then((version:VersionResource) => {if (version) {return this.buildItemsForVersion(version);} else {@@ -171,17 +97,13 @@ export class BoardVersionActionService implements BoardActionService {return value instanceof VersionResource && value.isOpen();}- public warningTextWhenNoOptionsAvailable() {- return Promise.resolve(undefined);- }-- private getVersions():Promise<VersionResource[]> {+ protected loadAvailable():Promise<VersionResource[]> {if (this.currentProject.id === null) {return Promise.resolve([]);}return this- .apiv3Service+ .apiV3Service.projects.id(this.currentProject.id!).versions@@ -191,7 +113,7 @@ export class BoardVersionActionService implements BoardActionService {}private patchVersionStatus(version:VersionResource, newStatus:'open'|'closed'|'locked') {- this.apiv3Service+ this.apiV3Service.versions.id(version).patch({ status: newStatus })diff --git a/frontend/src/app/modules/boards/board/board-list/board-list.component.ts b/frontend/src/app/modules/boards/board/board-list/board-list.component.tsindex e3acd0790fc..c59a9724f16 100644--- a/frontend/src/app/modules/boards/board/board-list/board-list.component.ts+++ b/frontend/src/app/modules/boards/board/board-list/board-list.component.ts@@ -239,7 +239,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnInipublic canMove(workPackage:WorkPackageResource) {if (this.board.isAction) {- return this.canDragOutOf && this.schema(workPackage).isAttributeEditable(this.board.actionAttribute!);+ return this.canDragOutOf && this.actionService.canMove(workPackage);} else {return this.canDragOutOf;}@@ -373,17 +373,8 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnInilet query = this.querySpace.query.value!;const changeset = this.halEditing.changeFor(workPackage) as WorkPackageChangeset;- // Ensure attribute remains writable in the form- const actionAttribute = this.board.actionAttribute;- if (actionAttribute && !changeset.isWritable(actionAttribute)) {- throw this.I18n.t(- 'js.boards.error_attribute_not_writable',- { attribute: changeset.humanName(actionAttribute) }- );- }-- const filter = new WorkPackageFilterValues(this.injector, changeset, query.filters);- filter.applyDefaultsFromFilters();+ // Assign to the action attribute if this is an action board+ this.actionService?.assignToWorkPackage(changeset, query);if (changeset.isEmpty()) {// Ensure work package and its schema is loaded@@ -413,7 +404,10 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIniobservable.subscribe(query => this.wpStatesInitialization.updateQuerySpace(query, query.results),- error => this.loadingError = this.halNotification.retrieveErrorMessage(error)+ error => {+ this.loadingError = this.halNotification.retrieveErrorMessage(error);+ this.cdRef.detectChanges();+ });}diff --git a/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts b/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.tsindex dbf5fed4378..cef15d4f243 100644--- a/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts+++ b/frontend/src/app/modules/boards/board/board-partitioned-page/board-list-container.component.ts@@ -20,6 +20,7 @@ import {AddListModalComponent} from "core-app/modules/boards/board/add-list-modaimport {I18nService} from "core-app/modules/common/i18n/i18n.service";import {BoardListCrossSelectionService} from "core-app/modules/boards/board/board-list/board-list-cross-selection.service";import {filter} from "rxjs/operators";+import {BoardActionsRegistryService} from "core-app/modules/boards/board/board-actions/board-actions-registry.service";import {APIV3Service} from "core-app/modules/apiv3/api-v3.service";@Component({@@ -74,6 +75,7 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implementsreadonly halNotification:HalResourceNotificationService,readonly boardComponent:BoardPartitionedPageComponent,readonly BoardList:BoardListsService,+ readonly boardActionRegistry:BoardActionsRegistryService,readonly opModalService:OpModalService,readonly injector:Injector,readonly apiV3Service:APIV3Service,@@ -196,11 +198,13 @@ export class BoardListContainerComponent extends UntilDestroyedMixin implementsprivate getActionFiltersFromWidget(board:Board):string[] {return board.grid.widgets.map(widget => {+ const service = this.boardActionRegistry.get(board.actionAttribute!);+ const filterName = service.filterName;const options:BoardWidgetOption = widget.options as any;- const filter = _.find(options.filters, (filter) => !!filter[board.actionAttribute!]);+ const filter = _.find(options.filters, (filter) => !!filter[filterName]);if (filter) {- return filter[board.actionAttribute!].values[0];+ return filter[filterName].values[0];}}).filter(value => !!value);diff --git a/frontend/src/app/modules/boards/board/query-updated/query-updated.service.ts b/frontend/src/app/modules/boards/board/query-updated/query-updated.service.tsindex 1ab00b4094a..35b8ec45cb7 100644--- a/frontend/src/app/modules/boards/board/query-updated/query-updated.service.ts+++ b/frontend/src/app/modules/boards/board/query-updated/query-updated.service.ts@@ -19,7 +19,8 @@ export class QueryUpdatedService {return interval(POLLING_INTERVAL).pipe(startWith(0),- filter(() => this.activeWindow.isActive),+ filter(() => ids.length > 0),+ filter(() => this.activeWindow.isActive),switchMap(() => {let result = this.queryForUpdates(ids, time);diff --git a/frontend/src/app/modules/boards/board/toolbar-menu/boards-toolbar-menu.directive.ts b/frontend/src/app/modules/boards/board/toolbar-menu/boards-toolbar-menu.directive.tsindex 4939ea671e0..ab363a89437 100644--- a/frontend/src/app/modules/boards/board/toolbar-menu/boards-toolbar-menu.directive.ts+++ b/frontend/src/app/modules/boards/board/toolbar-menu/boards-toolbar-menu.directive.ts@@ -107,7 +107,7 @@ export class BoardsToolbarMenuDirective extends OpContextMenuTrigger {this.boardService.delete(this.board).then(() => {- this.State.go('^', { flash_message: { type: 'success', message: this.text.deleteSuccessful } });+ this.State.go('boards.list', { flash_message: { type: 'success', message: this.text.deleteSuccessful } });});}diff --git a/frontend/src/app/modules/boards/boards-root/boards-root.component.ts b/frontend/src/app/modules/boards/boards-root/boards-root.component.tsindex f8192ede4f2..9ca28072bbe 100644--- a/frontend/src/app/modules/boards/boards-root/boards-root.component.ts+++ b/frontend/src/app/modules/boards/boards-root/boards-root.component.ts@@ -5,6 +5,7 @@ import {BoardStatusActionService} from "core-app/modules/boards/board/board-actiimport {BoardVersionActionService} from "core-app/modules/boards/board/board-actions/version/version-action.service";import {QueryUpdatedService} from "core-app/modules/boards/board/query-updated/query-updated.service";import {BoardAssigneeActionService} from "core-app/modules/boards/board/board-actions/assignee/assignee-action.service";+import {BoardSubprojectActionService} from "core-app/modules/boards/board/board-actions/subproject/subproject-action.service";@Component({selector: 'boards-entry',@@ -14,6 +15,7 @@ import {BoardAssigneeActionService} from "core-app/modules/boards/board/board-acBoardStatusActionService,BoardVersionActionService,BoardAssigneeActionService,+ BoardSubprojectActionService,QueryUpdatedService,]})@@ -26,9 +28,11 @@ export class BoardsRootComponent {const statusAction = injector.get(BoardStatusActionService);const versionAction = injector.get(BoardVersionActionService);const assigneeAction = injector.get(BoardAssigneeActionService);+ const subprojectAction = injector.get(BoardSubprojectActionService);registry.add('status', statusAction);registry.add('assignee', assigneeAction);registry.add('version', versionAction);+ registry.add('subproject', subprojectAction);}}diff --git a/frontend/src/app/modules/boards/openproject-boards.module.ts b/frontend/src/app/modules/boards/openproject-boards.module.tsindex cbe032a0bd5..0464d935e65 100644--- a/frontend/src/app/modules/boards/openproject-boards.module.ts+++ b/frontend/src/app/modules/boards/openproject-boards.module.ts@@ -51,6 +51,7 @@ import {BoardPartitionedPageComponent} from "core-app/modules/boards/board/boardimport {BoardListContainerComponent} from "core-app/modules/boards/board/board-partitioned-page/board-list-container.component";import {BoardsMenuButtonComponent} from "core-app/modules/boards/board/toolbar-menu/boards-menu-button.component";import {AssigneeBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/assignee/assignee-board-header.component";+import {SubprojectBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/subproject/subproject-board-header.component";@NgModule({imports: [@@ -86,6 +87,7 @@ import {AssigneeBoardHeaderComponent} from "core-app/modules/boards/board/board-BoardFilterComponent,VersionBoardHeaderComponent,AssigneeBoardHeaderComponent,+ SubprojectBoardHeaderComponent,]})export class OpenprojectBoardsModule {diff --git a/lib/api/v3/queries/schemas/only_subproject_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/only_subproject_filter_dependency_representer.rbnew file mode 100644index 00000000000..f11373ce535--- /dev/null+++ b/lib/api/v3/queries/schemas/only_subproject_filter_dependency_representer.rb@@ -0,0 +1,60 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module Queries+ module Schemas+ class OnlySubprojectFilterDependencyRepresenter <+ FilterDependencyRepresenter++ def json_cache_key+ if filter.project+ super + [filter.project.id]+ else+ super+ end+ end++ def href_callback+ params = [ancestor: { operator: '=', values: [filter.project.id.to_s] }]+ escaped = CGI.escape(::JSON.dump(params))++ "#{api_v3_paths.projects}?filters=#{escaped}"+ end++ def type+ "[]Project"+ end+ end+ end+ end+ end+enddiff --git a/modules/boards/config/locales/js-en.yml b/modules/boards/config/locales/js-en.ymlindex 4f283a217e1..1434fc45299 100644--- a/modules/boards/config/locales/js-en.yml+++ b/modules/boards/config/locales/js-en.yml@@ -47,6 +47,7 @@ en:assignee: assigneestatus: statusversion: version+ subproject: Subprojectselect_attribute: "Action attribute"add_list_modal: