-
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.
Merge pull request #17154 from opf/implementation/58524-render-full-b…
…ranch-of-hierarchy-item-value-assignment [#58524] render hierarchy items path in work package view
- Loading branch information
Showing
9 changed files
with
263 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
63 changes: 63 additions & 0 deletions
63
...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,63 @@ | ||
//-- 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) { | ||
const item = this.attribute as HalResource; | ||
if (item === null || item.name === this.texts.placeholder) { | ||
this.renderEmpty(element); | ||
return; | ||
} | ||
|
||
element.innerHTML = ''; | ||
element.classList.add('hierarchy-items'); | ||
|
||
this.branch(item).subscribe((path) => { | ||
element.appendChild(path); | ||
}); | ||
} | ||
|
||
private branch(item:HalResource):Observable<HTMLDivElement> { | ||
const itemLink = item.$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
70 changes: 70 additions & 0 deletions
70
...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,70 @@ | ||
//-- 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) { | ||
const items = this.attribute as HalResource[]; | ||
if (items.length === 0) { | ||
this.renderEmpty(element); | ||
return; | ||
} | ||
|
||
element.innerHTML = ''; | ||
element.classList.add('hierarchy-items'); | ||
this.branches(items).subscribe((elements) => { | ||
elements.forEach((el) => { | ||
element.appendChild(el); | ||
}); | ||
}); | ||
} | ||
|
||
public get valueString():string { | ||
return this.stringValue.join(', '); | ||
} | ||
|
||
private branches(items:HalResource[]):Observable<HTMLDivElement[]> { | ||
return combineLatest(items.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