1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 import { Component, OnInit } from '@angular/core';
\r
18 import { CookieService } from 'ngx-cookie-service';
\r
19 import { UserService } from 'app/shared/services/user.service';
\r
20 import { GroupService } from 'app/shared/services/group.service';
\r
21 import { routerTransition } from 'app/router.animations';
\r
22 import { AlertSnackbarComponent } from 'app/shared/modules/alert-snackbar/alert-snackbar.component';
\r
23 import { Group } from 'app/shared/models/group.model';
\r
24 import { MatSnackBar } from '@angular/material';
\r
27 selector: 'app-settings',
\r
28 templateUrl: './settings.component.pug',
\r
29 styleUrls: ['./settings.component.scss'],
\r
30 animations: [routerTransition()]
\r
33 export class SettingsComponent implements OnInit {
\r
34 defaultGroupEnabled = false;
\r
35 private defaultGroup;
\r
36 private eligibleGroups;
\r
37 private currentUser;
\r
38 private defaultGroupId;
\r
40 constructor(private cookie: CookieService,
\r
41 private user: UserService,
\r
42 private _group: GroupService,
\r
43 private snack: MatSnackBar
\r
48 this.currentUser = JSON.parse(this.cookie.get('currentUser'));
\r
50 this._group.find({ $limit: -1 }).subscribe((result) => {
\r
52 this.eligibleGroups = result;
\r
55 this.user.get(this.currentUser._id).subscribe((result) => {
\r
57 this.defaultGroupId = result['defaultGroup'];
\r
58 this.defaultGroupEnabled = result['defaultGroupEnabled'];
\r
60 this._group.get(this.defaultGroupId).subscribe((result) => {
\r
61 this.defaultGroup = result;
\r
66 changDefaultGroup(group: Group) {
\r
67 this.defaultGroup = group;
\r
70 enableDefaultGroup() {
\r
71 this.defaultGroupEnabled = true;
\r
74 disableDefaultGroup() {
\r
75 this.defaultGroupEnabled = false;
\r
81 this.currentUser.defaultGroupEnabled = this.defaultGroupEnabled;
\r
82 this.currentUser.defaultGroup = this.defaultGroup;
\r
83 this.cookie.set('currentUser', JSON.stringify(this.currentUser));
\r
88 _id: this.currentUser._id,
\r
89 defaultGroup: this.defaultGroup._id,
\r
90 defaultGroupEnabled: this.defaultGroupEnabled
\r
93 this.user.patch(userPatch).subscribe((res) => {
\r
94 let snackMessage = 'Successfully Updated Settings';
\r
95 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
98 message: snackMessage
\r