-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#58524] render hierarchy items path in work package view
- https://community.openproject.org/work_packages/58524 - write new display field classes for hierarchy items - amend display field service registry - fixed text representation of custom fields of type list - add branch link to hierarchy item representer
- Loading branch information
Showing
9 changed files
with
255 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...c/app/shared/components/fields/display/field-types/hierarchy-item-display-field.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//-- copyright | ||
// OpenProject is an open source project management software. | ||
// Copyright (C) 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 COPYRIGHT and LICENSE files for more details. | ||
//++ | ||
|
||
import { from, Observable } from 'rxjs'; | ||
import { switchMap } from 'rxjs/operators'; | ||
|
||
import { HalResource } from 'core-app/features/hal/resources/hal-resource'; | ||
import { HalLink } from 'core-app/features/hal/hal-link/hal-link'; | ||
import { | ||
ResourceDisplayField, | ||
} from 'core-app/shared/components/fields/display/field-types/resource-display-field.module'; | ||
import { renderHierarchyItem } from 'core-app/shared/components/fields/display/field-types/render-hierarchy-item'; | ||
|
||
export class HierarchyItemDisplayField extends ResourceDisplayField { | ||
public render(element:HTMLElement, _displayText:string) { | ||
element.innerHTML = ''; | ||
element.classList.add('hierarchy-items'); | ||
|
||
this.branch().subscribe((path) => { | ||
element.appendChild(path); | ||
}); | ||
} | ||
|
||
private branch():Observable<HTMLDivElement> { | ||
const attribute = this.attribute as HalResource; | ||
const itemLink = attribute.$link as HalLink; | ||
|
||
return from(itemLink.$fetch()) | ||
.pipe( | ||
switchMap((resource:HalResource) => renderHierarchyItem(resource)), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...mponents/fields/display/field-types/multiple-lines-hierarchy-item-display-field.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//-- copyright | ||
// OpenProject is an open source project management software. | ||
// Copyright (C) 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 COPYRIGHT and LICENSE files for more details. | ||
//++ | ||
|
||
import { combineLatest, from, Observable } from 'rxjs'; | ||
import { switchMap } from 'rxjs/operators'; | ||
|
||
import { HalResource } from 'core-app/features/hal/resources/hal-resource'; | ||
import { HalLink } from 'core-app/features/hal/hal-link/hal-link'; | ||
import { | ||
ResourcesDisplayField, | ||
} from 'core-app/shared/components/fields/display/field-types/resources-display-field.module'; | ||
import { renderHierarchyItem } from 'core-app/shared/components/fields/display/field-types/render-hierarchy-item'; | ||
|
||
export class MultipleLinesHierarchyItemDisplayField extends ResourcesDisplayField { | ||
public render(element:HTMLElement, _displayText:string) { | ||
element.innerHTML = ''; | ||
element.classList.add('hierarchy-items'); | ||
|
||
this.branches().subscribe((elements) => { | ||
elements.forEach((el) => { | ||
element.appendChild(el); | ||
}); | ||
}); | ||
} | ||
|
||
public get valueString():string { | ||
return this.stringValue.join(', '); | ||
} | ||
|
||
private branches():Observable<HTMLDivElement[]> { | ||
const attribute = this.attribute as HalResource[]; | ||
|
||
return combineLatest(attribute.map((value:HalResource) => { | ||
const itemLink = value.$link as HalLink; | ||
|
||
return from(itemLink.$fetch()) | ||
.pipe( | ||
switchMap((resource:HalResource) => renderHierarchyItem(resource)), | ||
); | ||
})); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
frontend/src/app/shared/components/fields/display/field-types/render-hierarchy-item.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//-- copyright | ||
// OpenProject is an open source project management software. | ||
// Copyright (C) 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 COPYRIGHT and LICENSE files for more details. | ||
//++ | ||
|
||
import { from, Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
import { HalResource } from 'core-app/features/hal/resources/hal-resource'; | ||
import { CollectionResource } from 'core-app/features/hal/resources/collection-resource'; | ||
|
||
export function renderHierarchyItem(item:HalResource):Observable<HTMLDivElement> { | ||
const customFieldItemLinks = item.$links as { branch:() => HalResource[] }; | ||
return from(customFieldItemLinks.branch()) | ||
.pipe( | ||
map((ancestors:CollectionResource) => spansFromAncestors(ancestors)), | ||
map((spans) => { | ||
const div = document.createElement('div'); | ||
div.className = 'path'; | ||
spans.forEach((span) => div.appendChild(span)); | ||
return div; | ||
}), | ||
); | ||
} | ||
|
||
function spansFromAncestors(ancestors:CollectionResource):HTMLSpanElement[] { | ||
const spans:HTMLSpanElement[] = []; | ||
|
||
ancestors.elements | ||
.filter((el) => !!el.label) | ||
.forEach((el, idx, all) => { | ||
const span = document.createElement('span'); | ||
span.textContent = el.label as string; | ||
spans.push(span); | ||
|
||
if (idx < all.length - 1) { | ||
const separator = document.createElement('span'); | ||
separator.textContent = '/'; | ||
spans.push(separator); | ||
} else if (el.short !== null) { | ||
const short = document.createElement('span'); | ||
short.textContent = `(${el.short})`; | ||
short.className = 'color-fg-subtle'; | ||
spans.push(short); | ||
} | ||
}); | ||
|
||
return spans; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters