2018-08-24 17:21:02 +02:00
|
|
|
import { DataTableRequest } from '../../models/data-table/DataTableRequest';
|
|
|
|
import { UserErrorModel } from '../../models/users/UserErrorModel';
|
|
|
|
import { UserReferenceService } from '../../services/user-reference/user-reference-data.service';
|
|
|
|
import { UserListingModel } from '../../models/users/UserListingModel';
|
|
|
|
import { SnackBarNotificationComponent } from '../../shared/components/notificaiton/snack-bar-notification.component';
|
|
|
|
import { UserCriteria } from '../../models/criteria/users/UserCriteria';
|
|
|
|
import { UserCriteriaErrorModel } from '../../models/criteria/users/UserCriteriaErrorModel';
|
|
|
|
import { Observable } from 'rxjs/Rx';
|
|
|
|
import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core';
|
|
|
|
import { UsersCriteriaComponent } from '../../shared/components/criteria/users/users-criteria.component';
|
|
|
|
import { Router, ActivatedRoute, Params } from '@angular/router';
|
|
|
|
import { Principal } from '../../models/login/Principal';
|
|
|
|
import { MatPaginator, MatSort, MatSnackBar } from '@angular/material';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import { DataSource } from '@angular/cdk/table';
|
|
|
|
import { RecentActivityTypes } from '../../users/activity/RecentActivityTypes';
|
|
|
|
import { AuthService } from '../../services/auth/auth.service';
|
2018-08-27 11:00:09 +02:00
|
|
|
import { DataManagementPlanModel } from '../../models/data-managemnt-plans/DataManagementPlanModel';
|
2018-08-30 13:09:36 +02:00
|
|
|
import { CultureInfo } from '../../utilities/culture/models/culture-info';
|
|
|
|
import { CultureService } from '../../utilities/culture/culture-service';
|
|
|
|
import { FormControl, FormBuilder, FormGroup } from '@angular/forms';
|
|
|
|
import * as moment from 'moment-timezone';
|
|
|
|
import { User } from '../../models/invitation/User';
|
2018-08-24 17:21:02 +02:00
|
|
|
|
2018-08-30 13:09:36 +02:00
|
|
|
const availableLanguages: any[] = require('../../../assets/resources/language.json');
|
2018-08-24 17:21:02 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-user-profile',
|
|
|
|
templateUrl: './user-profile.component.html',
|
|
|
|
styleUrls: ['./user-profile.component.scss'],
|
|
|
|
providers: [
|
2018-08-30 13:09:36 +02:00
|
|
|
UserReferenceService,
|
|
|
|
CultureService
|
2018-08-24 17:21:02 +02:00
|
|
|
]
|
|
|
|
})
|
|
|
|
export class UserProfileComponent implements OnInit {
|
|
|
|
|
|
|
|
user: Observable<UserListingModel>;
|
2018-08-27 11:00:09 +02:00
|
|
|
currentUserId: string;
|
2018-08-30 13:09:36 +02:00
|
|
|
cultures: Observable<CultureInfo[]>;
|
|
|
|
timezones: Observable<any[]>;
|
|
|
|
editMode = false;
|
|
|
|
languages = availableLanguages;
|
|
|
|
|
|
|
|
formGroup: FormGroup;
|
2018-08-24 17:21:02 +02:00
|
|
|
constructor(
|
|
|
|
private userReferenceService: UserReferenceService,
|
|
|
|
private route: ActivatedRoute,
|
2018-08-27 11:00:09 +02:00
|
|
|
private router: Router,
|
|
|
|
private authService: AuthService,
|
2018-08-30 13:09:36 +02:00
|
|
|
private language: TranslateService,
|
|
|
|
private cultureService: CultureService,
|
|
|
|
private translate: TranslateService,
|
2018-08-24 17:21:02 +02:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.route.params.subscribe((params: Params) => {
|
2018-08-27 11:00:09 +02:00
|
|
|
this.currentUserId = params['id'];
|
2018-08-24 17:21:02 +02:00
|
|
|
let userId = params['id'] === this.authService.current().id ? 'me' : params['id']
|
2018-08-30 13:09:36 +02:00
|
|
|
this.user = this.userReferenceService.getUser(userId).map(result => {
|
|
|
|
result["additionalinfo"] = JSON.parse(result["additionalinfo"]);
|
|
|
|
this.formGroup = new FormBuilder().group({
|
|
|
|
language: new FormControl(result["additionalinfo"]["language"] ? availableLanguages.filter(x => x.value === result["additionalinfo"]["language"]["value"]).pop() : ''),
|
|
|
|
timezone: new FormControl(result["additionalinfo"]["timezone"]),
|
|
|
|
culture: new FormControl(result["additionalinfo"]["culture"])
|
|
|
|
})
|
2018-08-31 10:14:56 +02:00
|
|
|
//this.formGroup.get('language').valueChanges.subscribe(x => { if (x) this.translate.use(x.value) })
|
2018-08-30 13:09:36 +02:00
|
|
|
this.formGroup.get('timezone').valueChanges.subscribe(x => { if (x) this.timezones = this._filterTimezone(x) });
|
|
|
|
this.formGroup.get('culture').valueChanges.subscribe(x => { if (x) this.cultures = this._filterCulture(x) });
|
|
|
|
this.formGroup.disable()
|
|
|
|
return result;
|
|
|
|
})
|
2018-08-27 11:00:09 +02:00
|
|
|
})
|
2018-08-30 13:09:36 +02:00
|
|
|
|
2018-08-27 11:00:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getUserRole(dmp: DataManagementPlanModel) {
|
|
|
|
if (dmp.creator.id === this.currentUserId) return this.language.instant('USER-PROFILE.DMPS.CREATOR')
|
|
|
|
else if (dmp.associatedUsers.map(x => x.id).indexOf(this.currentUserId) != -1) return this.language.instant('USER-PROFILE.DMPS.MEMBER');
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
|
|
|
|
showAllDmps() {
|
|
|
|
this.router.navigate(["/dmps"])
|
|
|
|
}
|
2018-08-24 17:21:02 +02:00
|
|
|
|
2018-08-27 11:00:09 +02:00
|
|
|
navigateToDmp(dmp: DataManagementPlanModel) {
|
|
|
|
this.router.navigate(["/dmps/edit/" + dmp.id])
|
|
|
|
}
|
2018-08-24 17:21:02 +02:00
|
|
|
|
2018-08-30 13:09:36 +02:00
|
|
|
private _filterTimezone(value: string): Observable<any[]> {
|
|
|
|
if (value && typeof value === 'string') {
|
|
|
|
const filterValue = value.toLowerCase();
|
|
|
|
return Observable.of(moment.tz.names().filter(option => option.toLowerCase().includes(filterValue)));
|
|
|
|
} else {
|
|
|
|
return Observable.of(moment.tz.names());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private _filterCulture(value: string): Observable<any[]> {
|
|
|
|
if (value && typeof value === 'string') {
|
|
|
|
const filterValue = value.toLowerCase();
|
|
|
|
return Observable.of(this.cultureService.getCultureValues().filter(option => option.displayName.toLowerCase().includes(filterValue)));
|
|
|
|
} else {
|
|
|
|
return Observable.of(this.cultureService.getCultureValues());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
displayFn(culture?: CultureInfo): string | undefined {
|
|
|
|
return culture ? culture.displayName + '-' + culture.nativeName : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public unlock() {
|
|
|
|
this.editMode = true;
|
|
|
|
this.formGroup.enable()
|
|
|
|
}
|
|
|
|
|
|
|
|
public lock() {
|
|
|
|
this.userReferenceService.updateUserSettings(this.formGroup.value).subscribe(
|
|
|
|
x => {
|
|
|
|
this.editMode = false;
|
2018-08-31 10:14:56 +02:00
|
|
|
this.translate.use(this.formGroup.value.language)
|
|
|
|
this.authService.current().culture = this.formGroup.value.culture.name
|
2018-08-30 13:09:36 +02:00
|
|
|
this.formGroup.disable();
|
2018-10-02 16:33:58 +02:00
|
|
|
this.authService.me().subscribe(x=> window.location.reload())
|
2018-08-30 13:09:36 +02:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
console.log(error)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-08-24 17:21:02 +02:00
|
|
|
}
|