Skip to content

Commit

Permalink
feat(admin): create new project and user if sys admin
Browse files Browse the repository at this point in the history
  • Loading branch information
kilchenmann committed May 3, 2019
1 parent 0a2fcaa commit b940e25
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ <h3 class="mat-body subtitle">
</span>
</div>
<div class="app-toolbar-row">
<h2 class="mat-title">{{list.length | i18nPlural: itemPluralMapping['title']}}</h2>
<span class="fill-remaining-space"></span>
<span class="app-toolbar-action button">
<span class="app-toolbar-action button left">
<!-- sort button if more than one item in the list -->
<kui-sort-button *ngIf="list.length > 1" [icon]="'sort_by_alpha'" [sortProps]="sortProps"
[(sortKey)]="sortBy" [position]="'right'">
</kui-sort-button>
[(sortKey)]="sortBy"></kui-sort-button>
</span>
<h2 class="mat-title">{{list.length | i18nPlural: itemPluralMapping['title']}}</h2>
<span class="fill-remaining-space"></span>
<span class="app-toolbar-action button right" *ngIf="status && createNew && sysAdmin">
<button mat-flat-button [color]="'primary'" (click)="openDialog('createProject')">Create new</button>
</span>
</div>
</div>
Expand Down
15 changes: 9 additions & 6 deletions src/app/system/projects/projects-list/projects-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ export class ProjectsListComponent implements OnInit {
// list of users: depending on the parent
@Input() list: User[];

// enable the button to create new project
@Input() createNew: boolean = false;

// in case of modification
@Output() refreshParent: EventEmitter<any> = new EventEmitter<any>();

// i18n plural mapping
itemPluralMapping = {
title: {
'=1': 'Project',
other: 'Projects'
'=1': '1 Project',
other: '# Projects'
}
};

Expand All @@ -56,11 +59,11 @@ export class ProjectsListComponent implements OnInit {
// ... and sort by 'shortname'
sortBy: string = 'shortname';

constructor(
constructor (
private _cache: CacheService,
private _dialog: MatDialog,
private _projectsService: ProjectsService,
private _router: Router) {}
private _router: Router) { }

ngOnInit() {
// get information about the logged-in user
Expand Down Expand Up @@ -108,11 +111,11 @@ export class ProjectsListComponent implements OnInit {
switch (mode) {
case 'deleteProject':
this.deleteProject(id);
break;
break;

case 'activateProject':
this.activateProject(id);
break;
break;
}
} else {
// update the view
Expand Down
3 changes: 2 additions & 1 deletion src/app/system/projects/projects.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

<div *ngIf="!loading">
<!-- <mat-divider></mat-divider> -->
<app-projects-list [list]="active" [status]="true" (refreshParent)="refresh()"></app-projects-list>
<app-projects-list [list]="active" [status]="true" (refreshParent)="refresh()" [createNew]="true">
</app-projects-list>

<!-- already archived projects: disable the menu -->
<app-projects-list [list]="inactive" [status]="false" (refreshParent)="refresh()"></app-projects-list>
Expand Down
156 changes: 78 additions & 78 deletions src/app/system/projects/projects.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class ProjectsComponent implements OnInit {
// list of archived (deleted) projects
inactive: Project[] = [];

constructor(
constructor (
private _cache: CacheService,
private _dialog: MatDialog,
private _projectsService: ProjectsService,
Expand Down Expand Up @@ -143,92 +143,65 @@ export class ProjectsComponent implements OnInit {
);
}
}
/*
initListBak() {
if (this.username) {
// get user's projects
this._cache
.get(
this.username,
this._usersService.getUserByUsername(this.username)
)
.subscribe(
(user: User) => {
// because of a knora cache issue, we have to make additional requests for each project
let i: number = 0;
for (const project of user.projects) {
this._projectsService
.getProjectByIri(project.id)
.subscribe(
(projectResponse: Project) => {
// this.projects.push(projectResponse);
for (const item of this.projects) {
if (item.status === true) {
this.active.push(item);
} else {
this.inactive.push(item);
/*
initListBak() {
if (this.username) {
// get user's projects
this._cache
.get(
this.username,
this._usersService.getUserByUsername(this.username)
)
.subscribe(
(user: User) => {
// because of a knora cache issue, we have to make additional requests for each project
let i: number = 0;
for (const project of user.projects) {
this._projectsService
.getProjectByIri(project.id)
.subscribe(
(projectResponse: Project) => {
// this.projects.push(projectResponse);
for (const item of this.projects) {
if (item.status === true) {
this.active.push(item);
} else {
this.inactive.push(item);
}
}
},
(projectError: ApiServiceError) => {
console.error(projectError);
}
},
(projectError: ApiServiceError) => {
console.error(projectError);
}
);
i++;
}
setTimeout(() => {
// console.log(this.resource);
this.loading = false;
}, 500);
},
(error: ApiServiceError) => {
console.error(error);
}
);
} else {
// system view if logged-in user is system admin
}
// check if the logged-in user is system admin
this.session = JSON.parse(localStorage.getItem('session'));
if (this.session.user.sysAdmin) {
this.loadSystem = true;
// the logged-in user is system administrator
// additional, get all projects
this._projectsService.getAllProjects().subscribe(
(projects: Project[]) => {
// this.systemProjects = projects;
);
i++;
}
for (const item of this.projects) {
if (item.status === true) {
this.active.push(item);
} else {
this.inactive.push(item);
setTimeout(() => {
// console.log(this.resource);
this.loading = false;
}, 500);
},
(error: ApiServiceError) => {
console.error(error);
}
}
this.loading = false;
},
(error: ApiServiceError) => {
console.error(error);
}
);
}
);
} else {
// system view if logged-in user is system admin
}
if (this.session && this.username === this.session.user.name) {
this.ownProfile = true;
// check if the logged-in user is system admin
this.session = JSON.parse(localStorage.getItem('session'));
if (this.session.user.sysAdmin) {
this.loadSystem = true;
// the logged-in user is system administrator
// additional, get all projects
this._projectsService.getAllProjects().subscribe(
(projects: Project[]) => {
this.systemProjects = projects;
// this.systemProjects = projects;
for (const item of this.projects) {
if (item.status === true) {
Expand All @@ -238,16 +211,43 @@ export class ProjectsComponent implements OnInit {
}
}
this.loadSystem = false;
this.loading = false;
},
(error: ApiServiceError) => {
console.error(error);
}
);
}
if (this.session && this.username === this.session.user.name) {
this.ownProfile = true;
if (this.session.user.sysAdmin) {
this.loadSystem = true;
// the logged-in user is system administrator
// additional, get all projects
this._projectsService.getAllProjects().subscribe(
(projects: Project[]) => {
this.systemProjects = projects;
for (const item of this.projects) {
if (item.status === true) {
this.active.push(item);
} else {
this.inactive.push(item);
}
}
this.loadSystem = false;
},
(error: ApiServiceError) => {
console.error(error);
}
);
}
}
}
}
*/
*/
openDialog(mode: string): void {
const dialogConfig: MatDialogConfig = {
width: '560px',
Expand Down
12 changes: 7 additions & 5 deletions src/app/system/users/users-list/users-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ <h3 class="mat-body subtitle">
</span>
</div>
<div class="app-toolbar-row">
<h2 class="mat-title">{{list.length | i18nPlural: itemPluralMapping['title']}}</h2>
<span class="fill-remaining-space"></span>
<span class="app-toolbar-action button">
<span class="app-toolbar-action button left">
<!-- sort button if more than one item in the list -->
<kui-sort-button *ngIf="list.length > 1" [icon]="'sort_by_alpha'" [sortProps]="sortProps"
[(sortKey)]="sortBy" [position]="'right'">
</kui-sort-button>
[(sortKey)]="sortBy"></kui-sort-button>
</span>
<h2 class="mat-title">{{list.length | i18nPlural: itemPluralMapping['title']}}</h2>
<span class="fill-remaining-space"></span>
<span class="app-toolbar-action button right" *ngIf="status && createNew && sysAdmin">
<button mat-flat-button [color]="'primary'" (click)="openDialog('createUser')">Create new</button>
</span>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/app/system/users/users-list/users-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class UsersListComponent implements OnInit {
// list of users: depending on the parent
@Input() list: User[];

// enable the button to create new user
@Input() createNew: boolean = false;

// in case of modification
@Output() refreshParent: EventEmitter<any> = new EventEmitter<any>();

Expand Down
2 changes: 1 addition & 1 deletion src/app/system/users/users.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div *ngIf="!loading">

<!-- list of active users -->
<app-users-list [list]="active" [status]="true" (refreshParent)="refresh()"></app-users-list>
<app-users-list [list]="active" [status]="true" (refreshParent)="refresh()" [createNew]="true"></app-users-list>

<!-- <mat-divider class="more-space"></mat-divider> -->

Expand Down
10 changes: 6 additions & 4 deletions src/app/user/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ <h2 class="mat-title">Here you'll find your latest work and your projects</h2>

<div class="app-toolbar transparent">
<div class="app-toolbar-row">
<h3 class="mat-body subtitle" >List of projects</h3>
<h3 class="mat-body subtitle">List of projects</h3>
</div>
<div class="app-toolbar-row">
<h2 class="mat-title">
<span *ngIf="!showSystemProjects">These are your projects</span>
<span *ngIf="showSystemProjects && sysAdmin">As a system admin you have access to all projects</span>
<span *ngIf="!showSystemProjects">You are member in the following projects</span>
<span *ngIf="showSystemProjects && sysAdmin">As a system admin you have access to all
projects</span>
</h2>
<span class="fill-remaining-space"></span>
<span class="app-toolbar-action">
<button mat-button color="'primary'" *ngIf="sysAdmin" (click)="showSystemProjects = !showSystemProjects" class="toggle-view">
<button mat-button color="'primary'" *ngIf="sysAdmin"
(click)="showSystemProjects = !showSystemProjects" class="toggle-view">
<span *ngIf="showSystemProjects">Show only my projects</span>
<span *ngIf="!showSystemProjects">Show all projects</span>
</button>
Expand Down
2 changes: 1 addition & 1 deletion src/app/user/user-form/user-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</mat-form-field>

<div class="large-field">
<mat-slide-toggle [formControl]="form.controls['newSystemAdminMembershipStatus']">
<mat-slide-toggle [formControl]="form.controls['systemAdmin']">
{{ 'appLabels.form.user.general.sysAdmin' | translate }}
</mat-slide-toggle>
</div>
Expand Down
19 changes: 10 additions & 9 deletions src/app/user/user-form/user-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ export class UserFormComponent implements OnInit, OnChanges {
value: user.status ? user.status : true,
disabled: editMode
}),
newSystemAdminMembershipStatus: new FormControl({
systemAdmin: new FormControl({
value: this.sysAdminPermission,
disabled: false
disabled: editMode
})
// 'systemAdmin': this.sysAdminPermission,
// 'group': null
Expand Down Expand Up @@ -525,14 +525,15 @@ export class UserFormComponent implements OnInit, OnChanges {
}
);
} else {
// go to user's profile page
this.closeMessage();
this.loading = false;
// redirect to (new) user's page
this._router
.navigateByUrl('/user', {
skipLocationChange: true
})
.then(() => this._router.navigate([returnUrl]));

/* // redirect to (new) user's page
this._router
.navigateByUrl('/user', {
skipLocationChange: true
})
.then(() => this._router.navigate([returnUrl])); */
}
},
(error: ApiServiceError) => {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"step_4": "Confirm",
"more": "Add more users"
},
"add2project": "Add new member",
"add2project": "Add member",
"select": "Select from list...",
"create": "or create new one",
"deleted": "already deleted"
Expand Down
Loading

0 comments on commit b940e25

Please sign in to comment.