New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(lists): read mode project member (DEV-1343) #825
Changes from 11 commits
a06b1e1
bd652a0
97da899
b782535
b73ed1e
fb5d97f
9ddbb19
418b6d0
7d014f3
19116da
fd7bb22
cd87150
ff8b5a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,14 @@ import { | |
ListInfoResponse, | ||
ListNode, | ||
ListNodeInfoResponse, | ||
ReadProject, | ||
StringLiteral | ||
} from '@dasch-swiss/dsp-js'; | ||
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens'; | ||
import { DialogComponent } from 'src/app/main/dialog/dialog.component'; | ||
import { ErrorHandlerService } from 'src/app/main/services/error-handler.service'; | ||
import { Session, SessionService } from '../../../main/services/session.service'; | ||
import { CacheService } from '../../../main/cache/cache.service'; | ||
|
||
export class ListNodeOperation { | ||
operation: 'create' | 'insert' | 'update' | 'delete' | 'reposition'; | ||
|
@@ -90,6 +93,14 @@ export class ListItemFormComponent implements OnInit { | |
|
||
@Output() refreshParent: EventEmitter<ListNodeOperation> = new EventEmitter<ListNodeOperation>(); | ||
|
||
// permissions of logged-in user | ||
session: Session; | ||
sysAdmin = false; | ||
projectAdmin = false; | ||
|
||
// project data | ||
project: ReadProject; | ||
|
||
loading: boolean; | ||
|
||
initComponent: boolean; | ||
|
@@ -101,10 +112,30 @@ export class ListItemFormComponent implements OnInit { | |
constructor( | ||
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection, | ||
private _errorHandler: ErrorHandlerService, | ||
private _dialog: MatDialog | ||
private _dialog: MatDialog, | ||
private _session: SessionService, | ||
private _cache: CacheService, | ||
) { } | ||
|
||
ngOnInit() { | ||
// get information about the logged-in user | ||
this.session = this._session.getSession(); | ||
|
||
// is the logged-in user system admin? | ||
this.sysAdmin = this.session.user.sysAdmin; | ||
|
||
// get the project data from cache | ||
this._cache.get(this.projectCode).subscribe( | ||
(response: ReadProject) => { | ||
this.project = response; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would go further and not even use |
||
|
||
// is logged-in user projectAdmin? | ||
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id); | ||
}, | ||
(error: ApiResponseError) => { | ||
this._errorHandler.showMessage(error); | ||
} | ||
); | ||
|
||
this.initComponent = true; | ||
|
||
|
@@ -199,7 +230,9 @@ export class ListItemFormComponent implements OnInit { | |
* show action bubble with various CRUD buttons when hovered over. | ||
*/ | ||
mouseEnter() { | ||
this.showActionBubble = true; | ||
if (this.projectAdmin) { | ||
this.showActionBubble = true; | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,28 @@ | |
<div class="list-node" *ngFor="let node of list; let first = first; let last = last;"> | ||
|
||
<!-- button to expand / close node --> | ||
<button type="button" mat-icon-button (click)="toggleChildren(node.id)" class=""> | ||
<button *ngIf="node.children.length !== 0" type="button" mat-icon-button (click)="toggleChildren(node.id)"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This causes the arrow to be hidden even for project admins. The arrow needs to be shown for project admins so that they can add child node even if one doesn't already exist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in cd87150 |
||
<mat-icon class="mat-icon-rtl-mirror"> | ||
{{showChildren(node.id) ? 'expand_more' : 'chevron_right'}} | ||
</mat-icon> | ||
</button> | ||
|
||
<div class="list-item-indentation" *ngIf="node.children.length === 0"></div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing this, I would add a conditional class on the button above in the event that the node has no children. Something like [class.list-item-indentation]="node.children.length === 0". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried with the class condition but couldn't do it. So I changed the whole situation by adding a div around the button with a certain size -> cd87150 |
||
|
||
<!-- existing node: show label in form; value is e.g. {{node.labels[0].value}} --> | ||
<app-list-item-form [iri]="node.id" [language]="language" (refreshParent)="updateView($event, true)" | ||
[projectIri]="projectIri" [projectCode]="projectCode" [projectStatus]="projectStatus" [labels]="node.labels" | ||
[position]="node.position" [lastPosition]="last" [parentIri]="parentIri"> | ||
</app-list-item-form> | ||
|
||
|
||
<!-- recursion: list with child nodes --> | ||
<app-list-item class="child-node" *ngIf="node.id === expandedNode && node.children.length > 0" | ||
[language]="language" [childNode]="true" [list]="node.children" [parentIri]="node.id" | ||
[projectIri]="projectIri" [projectCode]="projectCode" [projectStatus]="projectStatus" (refreshChildren)="updateParentNodeChildren($event, node.position)"> | ||
</app-list-item> | ||
|
||
|
||
<!-- in case of none children: show form to append new item --> | ||
<div *ngIf="node.id === expandedNode && node.children.length === 0 && projectStatus" class="child-node"> | ||
<!-- in case of none children: show form to append new item --> | ||
<div class="child-node" *ngIf="node.id === expandedNode && node.children.length === 0 && projectStatus && projectAdmin"> | ||
<!-- first child should have an empty list? yes --> | ||
<app-list-item-form class="append-child-node" [parentIri]="node.id" [projectIri]="projectIri" | ||
[projectCode]="projectCode" [language]="language" [newNode]="true" | ||
|
@@ -32,7 +32,7 @@ | |
</div> | ||
|
||
<!-- form to append new item to parent node --> | ||
<app-list-item-form class="list-node append-child-node" *ngIf="last && projectStatus" [parentIri]="parentIri" | ||
<app-list-item-form class="list-node append-child-node" *ngIf="last && projectStatus && projectAdmin" [parentIri]="parentIri" | ||
[projectIri]="projectIri" [projectCode]="projectCode" [language]="language" | ||
[newNode]="true" (refreshParent)="updateView($event)"> | ||
</app-list-item-form> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,15 @@ import { | |
ListChildNodeResponse, | ||
ListNode, | ||
ListResponse, | ||
ReadProject, | ||
RepositionChildNodeRequest, | ||
RepositionChildNodeResponse | ||
RepositionChildNodeResponse, | ||
} from '@dasch-swiss/dsp-js'; | ||
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens'; | ||
import { ErrorHandlerService } from 'src/app/main/services/error-handler.service'; | ||
import { ListNodeOperation } from '../list-item-form/list-item-form.component'; | ||
import { Session, SessionService } from '../../../main/services/session.service'; | ||
import { CacheService } from '../../../main/cache/cache.service'; | ||
|
||
@Component({ | ||
selector: 'app-list-item', | ||
|
@@ -36,14 +39,43 @@ export class ListItemComponent implements OnInit { | |
|
||
@Output() refreshChildren: EventEmitter<ListNode[]> = new EventEmitter<ListNode[]>(); | ||
|
||
// permissions of logged-in user | ||
session: Session; | ||
sysAdmin = false; | ||
projectAdmin = false; | ||
|
||
// project data | ||
project: ReadProject; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing here as in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
expandedNode: string; | ||
|
||
constructor( | ||
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection, | ||
private _errorHandler: ErrorHandlerService | ||
private _errorHandler: ErrorHandlerService, | ||
private _session: SessionService, | ||
private _cache: CacheService, | ||
) { } | ||
|
||
ngOnInit() { | ||
// get information about the logged-in user | ||
this.session = this._session.getSession(); | ||
|
||
// is the logged-in user system admin? | ||
this.sysAdmin = this.session.user.sysAdmin; | ||
|
||
// get the project data from cache | ||
this._cache.get(this.projectCode).subscribe( | ||
(response: ReadProject) => { | ||
this.project = response; | ||
|
||
// is logged-in user projectAdmin? | ||
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id); | ||
}, | ||
(error: ApiResponseError) => { | ||
this._errorHandler.showMessage(error); | ||
} | ||
); | ||
|
||
// in case of parent node: run the following request to get the entire list | ||
if (!this.childNode) { | ||
this._dspApiConnection.admin.listsEndpoint.getList(this.parentIri).subscribe( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this variable is needed, you can use a
const
to temporarily store the project you get from the cacheThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, it is not needed elsewhere (ff8b5a8)