fixed locale dates
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
import {Component, OnInit, Inject, Input} from '@angular/core';
|
||||
import {Sort} from '@angular/material/sort';
|
||||
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
|
||||
import {ConfirmDialog} from '../confirm/confirm.component';
|
||||
import {I18nService} from '../../services/i18n.service';
|
||||
import {ProfileService} from '../../services/profile.service';
|
||||
import {ProfileFieldPgpBlob} from './binary/pgp/profilefield.pgp-blob';
|
||||
import { Component, OnInit, Inject, Input } from '@angular/core';
|
||||
import { Sort } from '@angular/material/sort';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { ConfirmDialog } from '../confirm/confirm.component';
|
||||
import { I18nService } from '../../services/i18n.service';
|
||||
import { ProfileService } from '../../services/profile.service';
|
||||
import { ProfileFieldPgpBlob } from './binary/pgp/profilefield.pgp-blob';
|
||||
|
||||
@Component({
|
||||
selector: 'app-profilefields',
|
||||
templateUrl: './profilefields.component.html',
|
||||
styleUrls: ['./profilefields.component.scss']
|
||||
styleUrls: [ './profilefields.component.scss' ]
|
||||
})
|
||||
export class ProfileFieldsComponent implements OnInit {
|
||||
|
||||
@Input() username;
|
||||
@Input() edit;
|
||||
profileFieldColumns = ["name", "value"];
|
||||
profileFieldColumns = [ "name", "value" ];
|
||||
profileFields: Array<any> = [];
|
||||
datetimeformat: String;
|
||||
dateformat: String;
|
||||
timeformat: String;
|
||||
|
||||
constructor(private i18n: I18nService, private profileService: ProfileService, public dialog: MatDialog) {}
|
||||
constructor(private i18n: I18nService, private profileService: ProfileService, public dialog: MatDialog) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
if(this.edit) {
|
||||
if (this.edit) {
|
||||
this.profileFieldColumns.push("visibility");
|
||||
this.profileFieldColumns.push("edit");
|
||||
this.profileFieldColumns.push("delete");
|
||||
@@ -40,7 +40,7 @@ export class ProfileFieldsComponent implements OnInit {
|
||||
|
||||
|
||||
update() {
|
||||
if(this.username) {
|
||||
if (this.username) {
|
||||
this.profileService.getForUser(this.username).subscribe((data: any) => {
|
||||
this.profileFields = data.profileFields;
|
||||
})
|
||||
@@ -53,14 +53,14 @@ export class ProfileFieldsComponent implements OnInit {
|
||||
|
||||
sortData(sort: Sort) {
|
||||
const data = this.profileFields.slice();
|
||||
if(!sort.active || sort.direction === '') {
|
||||
if (!sort.active || sort.direction === '') {
|
||||
this.profileFields = data;
|
||||
return;
|
||||
}
|
||||
|
||||
this.profileFields = data.sort((a, b) => {
|
||||
const isAsc = sort.direction === 'asc';
|
||||
switch(sort.active) {
|
||||
switch (sort.active) {
|
||||
case 'name': return this.compare(this.i18n.getEmpty('profileField.name.' + a.name, []), this.i18n.getEmpty('profileField.name.' + b.name, []), isAsc);
|
||||
case 'value': return this.compare(a.value, b.value, isAsc);
|
||||
case 'index': return this.compare(a.index, b.index, isAsc);
|
||||
@@ -70,9 +70,9 @@ export class ProfileFieldsComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
compare(a: number | string , b: number | string , isAsc: boolean) {
|
||||
compare(a: number | string, b: number | string, isAsc: boolean) {
|
||||
if (typeof a === 'string' && typeof b === 'string') {
|
||||
return a.localeCompare(b,undefined, { sensitivity: 'accent' } ) * (isAsc ? 1 : -1);
|
||||
return a.localeCompare(b, undefined, { sensitivity: 'accent' }) * (isAsc ? 1 : -1);
|
||||
}
|
||||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ export class ProfileFieldsComponent implements OnInit {
|
||||
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if(result) {
|
||||
if (result) {
|
||||
this.profileService.createOrUpdate(result).subscribe();
|
||||
} else {
|
||||
profileField.name = resetProfileField.name;
|
||||
@@ -105,13 +105,13 @@ export class ProfileFieldsComponent implements OnInit {
|
||||
const dialogRef = this.dialog.open(ConfirmDialog, {
|
||||
data: {
|
||||
'label': 'profileField.confirmDelete',
|
||||
'empty' : true,
|
||||
'args': ['profileField.name.' + profileField.name]
|
||||
'empty': true,
|
||||
'args': [ 'profileField.name.' + profileField.name ]
|
||||
}
|
||||
})
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if(result) {
|
||||
if (result) {
|
||||
this.profileService.delete(profileField.name).subscribe((result: any) => {
|
||||
this.update();
|
||||
})
|
||||
@@ -121,12 +121,12 @@ export class ProfileFieldsComponent implements OnInit {
|
||||
|
||||
openCreate() {
|
||||
const dialogRef = this.dialog.open(ProfileFieldDialog, {
|
||||
data: {"type": "TEXT", "visibility": "PRIVATE"},
|
||||
data: { "type": "TEXT", "visibility": "PRIVATE" },
|
||||
minWidth: '400px'
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if(result) {
|
||||
if (result) {
|
||||
this.update();
|
||||
}
|
||||
});
|
||||
@@ -145,19 +145,19 @@ export class ProfileFieldsComponent implements OnInit {
|
||||
@Component({
|
||||
selector: 'app-profilefield-dialog',
|
||||
templateUrl: 'profilefield.dialog.html',
|
||||
styleUrls: ['./profilefield.dialog.scss']
|
||||
styleUrls: [ './profilefield.dialog.scss' ]
|
||||
})
|
||||
export class ProfileFieldDialog {
|
||||
|
||||
form: FormGroup;
|
||||
profileField;
|
||||
|
||||
types = ["TEXT", "NUMBER", "DATE", "DATETIME", "URL", "EMAIL", "BOOL", "BLOB"];
|
||||
visibilities = ["PRIVATE", "PROTECTED", "PUBLIC"];
|
||||
types = [ "TEXT", "NUMBER", "DATE", "DATETIME", "URL", "EMAIL", "BOOL", "BLOB" ];
|
||||
visibilities = [ "PRIVATE", "PROTECTED", "PUBLIC" ];
|
||||
|
||||
constructor(
|
||||
private profileService: ProfileService,
|
||||
private formBuilder: FormBuilder,
|
||||
private formBuilder: FormBuilder,
|
||||
private dialog: MatDialog,
|
||||
public dialogRef: MatDialogRef<ProfileFieldDialog>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any) {
|
||||
@@ -166,17 +166,17 @@ export class ProfileFieldDialog {
|
||||
|
||||
ngOnInit() {
|
||||
this.form = this.formBuilder.group({
|
||||
name: ['', Validators.required],
|
||||
type: ['', Validators.required],
|
||||
value: [''],
|
||||
blob: [''],
|
||||
visibility: ['', Validators.required],
|
||||
index: ['']
|
||||
name: [ '', Validators.required ],
|
||||
type: [ '', Validators.required ],
|
||||
value: [ '' ],
|
||||
blob: [ '' ],
|
||||
visibility: [ '', Validators.required ],
|
||||
index: [ '' ]
|
||||
});
|
||||
}
|
||||
|
||||
booleanChange(profileField) {
|
||||
if(profileField.value == 'true') {
|
||||
if (profileField.value == 'true') {
|
||||
profileField.value = 'false';
|
||||
} else {
|
||||
profileField.value = 'true';
|
||||
@@ -188,15 +188,15 @@ export class ProfileFieldDialog {
|
||||
this.profileService.createOrUpdate(profileField).subscribe((result: any) => {
|
||||
this.dialogRef.close(profileField);
|
||||
}, (error) => {
|
||||
if(error.status == 409) {
|
||||
if (error.status == 409) {
|
||||
let errors = {};
|
||||
for(let code of error.error) {
|
||||
errors[code.field] = errors[code.field] || {};
|
||||
errors[code.field][code.code] = true;
|
||||
for (let code of error.error) {
|
||||
errors[ code.field ] = errors[ code.field ] || {};
|
||||
errors[ code.field ][ code.code ] = true;
|
||||
}
|
||||
|
||||
for(let code in errors) {
|
||||
this.form.get(code).setErrors(errors[code]);
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[ code ]);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -208,8 +208,7 @@ export class ProfileFieldDialog {
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if(result) {
|
||||
console.log(result, profileField);
|
||||
if (result) {
|
||||
profileField.blob = result;
|
||||
}
|
||||
});
|
||||
@@ -222,7 +221,7 @@ export class ProfileFieldDialog {
|
||||
@Component({
|
||||
selector: 'app-profilefield-blob',
|
||||
templateUrl: 'profilefield.blob.html',
|
||||
styleUrls: ['./profilefield.blob.scss']
|
||||
styleUrls: [ './profilefield.blob.scss' ]
|
||||
})
|
||||
export class ProfileFieldBlob {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user