Skip to content

Commit 7e4929d

Browse files
committed
[NAE-2072] Workspaces
- change funcionality
1 parent c9b3599 commit 7e4929d

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

projects/netgrif-components-core/src/lib/navigation/navigation-double-drawer/abstract-navigation-double-drawer.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {MatDrawerMode} from '@angular/material/sidenav';
44
import {ActivatedRoute, Router} from '@angular/router';
55
import {ResizeEvent} from 'angular-resizable-element';
66
import {Observable, of, Subject, Subscription} from 'rxjs';
7-
import {map} from 'rxjs/operators';
7+
import {map, tap} from 'rxjs/operators';
88
import {RoleAccess, View} from '../../../commons/schema';
99
import {AccessService} from '../../authorization/permission/access.service';
1010
import {ConfigurationService} from '../../configuration/configuration.service';
@@ -43,6 +43,7 @@ import {
4343
RIGHT_SIDE_NEW_PAGE_SIZE,
4444
SETTINGS_TRANSITION_ID
4545
} from '../model/navigation-configs';
46+
import {Workspace} from "../../user/models/workspace";
4647

4748

4849
@Component({
@@ -117,7 +118,8 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
117118
};
118119

119120
protected _childCustomViews: { [uri: string]: { [key: string]: NavigationItem } };
120-
public userWorkspaces$: Observable<Array<string>>;
121+
public userWorkspaces$: Observable<Array<Workspace>>;
122+
public userWorkspacesLength: number;
121123

122124
protected constructor(protected _router: Router,
123125
protected _activatedRoute: ActivatedRoute,
@@ -165,6 +167,10 @@ export abstract class AbstractNavigationDoubleDrawerComponent implements OnInit,
165167
this.resolveHiddenMenuItemFromChildViews(viewConfigurationPath + '/' + key, childView);
166168
});
167169
}
170+
171+
this.userWorkspaces$ = this._userService.workspaces$.pipe(
172+
tap(arr => this.userWorkspacesLength = arr.length)
173+
);
168174
}
169175

170176
get currentNode(): UriNodeResource {

projects/netgrif-components-core/src/lib/resources/engine-endpoint/user-resource.service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,19 @@ export class UserResourceService extends AbstractResourceService {
7878
* **Request URL:** {{baseUrl}}/api/user/workspaces
7979
*/
8080
public getAllWorkspaces(params?: Params): Observable<Array<Workspace>> {
81-
return this._resourceProvider.get$('user/workspaces', this.SERVER_URL, params)
81+
return this._resourceProvider.get$('users/workspaces', this.SERVER_URL, params)
82+
.pipe(map(r => this.changeType(r, undefined)));
83+
}
84+
85+
/**
86+
* Get all workspaces
87+
*
88+
* **Request Type:** GET
89+
*
90+
* **Request URL:** {{baseUrl}}/api/user/workspaces
91+
*/
92+
public changeWorkspace(workspaceId: string, params?: Params): Observable<UserResource> {
93+
return this._resourceProvider.post$('users/workspace', this.SERVER_URL, {workspaceId}, params)
8294
.pipe(map(r => this.changeType(r, undefined)));
8395
}
8496

projects/netgrif-components-core/src/lib/user/services/user.service.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class UserService implements OnDestroy {
2626
protected _subAuth: Subscription;
2727
protected _subAnonym: Subscription;
2828
private _publicLoadCalled: boolean;
29-
protected _workspaces: BehaviorSubject<Array<Workspace>>;
29+
protected _workspaces: ReplaySubject<Array<Workspace>>;
3030

3131
public readonly GLOBAL_ROLE_PREFIX = 'global_';
3232

@@ -39,11 +39,14 @@ export class UserService implements OnDestroy {
3939
this._user = this.emptyUser();
4040
this._loginCalled = false;
4141
this._userChange$ = new ReplaySubject<User>(1);
42+
this._workspaces = new ReplaySubject<Array<Workspace>>(1);
4243
this._anonymousUserChange$ = new ReplaySubject<User>(1);
4344
setTimeout(() => {
4445
this._subAuth = this._authService.authenticated$.subscribe(auth => {
4546
if (auth && !this._loginCalled) {
4647
this.loadUser();
48+
} else if (auth && this._loginCalled) {
49+
this.loadWorkspaces();
4750
} else if (!auth) {
4851
this.clearUser();
4952
this.publishUserChange();
@@ -68,10 +71,6 @@ export class UserService implements OnDestroy {
6871
return this._userChange$.asObservable();
6972
}
7073

71-
get workspaces() {
72-
return this._workspaces.getValue();
73-
}
74-
7574
get workspaces$(): Observable<Array<Workspace>> {
7675
return this._workspaces.asObservable();
7776
}
@@ -232,7 +231,7 @@ export class UserService implements OnDestroy {
232231
}
233232

234233
public changeWorkspace(workspaceId: string) {
235-
this._userResource.updateUser(this.user.id, {workspaceId}).subscribe(user => {
234+
this._userResource.changeWorkspace(workspaceId).subscribe(user => {
236235
if (user) {
237236
const backendUser = {...user, id: user.id.toString()};
238237
this._user = this._userTransform.transform(backendUser);

projects/netgrif-components/src/lib/navigation/navigation-double-drawer/navigation-double-drawer.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@
115115
</div>
116116

117117
<mat-menu #activeWorkspaceMenu="matMenu" overlapTrigger="false" xPosition="after" yPosition="above">
118-
<button *ngFor='let workspace of userWorkspaces$ | async' mat-menu-item (click)="setWorkspace(workspace)"
119-
[ngClass]="{'menu-button-selected': workspace === activeWorkspace()}">
120-
{{ workspace }}
118+
<button *ngFor='let workspace of userWorkspaces$ | async' mat-menu-item (click)="setWorkspace(workspace.id)"
119+
[ngClass]="{'menu-button-selected': workspace.id === activeWorkspace()}">
120+
{{ workspace.id + (workspace.defaultWorkspace ? " (D)" : "")}}
121121
</button>
122122
</mat-menu>
123123

124-
<button mat-icon-button
124+
<button mat-icon-button *ngIf="userWorkspacesLength > 1"
125125
[matMenuTriggerFor]="activeWorkspaceMenu"
126126
class="menu-button mat-typography menu-font-color margin-top-default"
127127
[matTooltip]="'drawer.selectedGroup' | translate"

projects/netgrif-components/src/lib/navigation/navigation.theme.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
}
2020
}
2121

22+
.menu-button-selected {
23+
olor: mat.get-color-from-palette($primary) !important;
24+
}
25+
2226
.rail-color {
2327
background: #F8FAFC;
2428
}

0 commit comments

Comments
 (0)