192 lines
5.6 KiB
TypeScript
192 lines
5.6 KiB
TypeScript
import { Component, OnInit } from "@angular/core";
|
||
import { JsonrpcService, RpcService } from "src/app/services/jsonrpc.service";
|
||
import { MessageService } from "primeng/api";
|
||
import { Divisions } from "src/app/interface/data";
|
||
import { ConfirmationService, FilterService, FilterMatchMode, SelectItem } from 'primeng/api';
|
||
|
||
|
||
@Component({
|
||
selector: 'app-divisions',
|
||
templateUrl: './divisions.component.html',
|
||
styleUrls: ['./divisions.component.scss']
|
||
})
|
||
export class DivisionsComponent implements OnInit {
|
||
public divisions: Divisions[] = [];
|
||
public new_div = true;
|
||
public choose = this.jsonRpcService.ClientChoose;
|
||
public create = false;
|
||
public chooseName!: string;
|
||
public ind: boolean = false;
|
||
public matchModeOptions!: SelectItem[];
|
||
|
||
constructor(
|
||
private jsonRpcService: JsonrpcService,
|
||
private messageService: MessageService,
|
||
private confirmationService: ConfirmationService,
|
||
private filterService: FilterService
|
||
) { }
|
||
|
||
ngOnInit(): void {
|
||
if (this.choose) { this.getDivisions() };
|
||
|
||
const customFilterName = "custom-contains";
|
||
this.filterService.register(customFilterName, (value: any, filter: any): boolean => {
|
||
if (filter === undefined || filter === null || filter.trim() === '') {
|
||
return true;
|
||
}
|
||
|
||
if (value === undefined || value === null) {
|
||
return false;
|
||
}
|
||
let det = value.toString()
|
||
let det2 = det.toLowerCase()
|
||
return det2.includes(filter.toString()) || det.includes(filter.toString());
|
||
|
||
});
|
||
|
||
this.matchModeOptions = [
|
||
{ label: 'Содержит', value: customFilterName },
|
||
{ label: 'Равно', value: FilterMatchMode.EQUALS },
|
||
{ label: 'Начинается с', value: FilterMatchMode.STARTS_WITH },
|
||
];
|
||
}
|
||
|
||
async getDivisions() {
|
||
this.create = false;
|
||
this.new_div = true;
|
||
await this.jsonRpcService.rpc2({
|
||
method: 'getDivisions',
|
||
params: {
|
||
"client_id": this.choose
|
||
}
|
||
}, RpcService.authService, false)
|
||
.subscribe({
|
||
next: (result) => {
|
||
let data = result.result;
|
||
this.divisions = data;
|
||
document.getElementsByTagName('thead')[0].style.display = 'table';
|
||
document.getElementsByTagName('thead')[0].style.width = '100%';
|
||
document.getElementsByTagName('thead')[0].style.tableLayout = 'fixed';
|
||
document.getElementsByTagName('tbody')[0].style.display = 'block';
|
||
document.getElementsByTagName('tbody')[0].style.maxHeight = 'calc(100vh - 290px)';
|
||
document.getElementsByTagName('tbody')[0].style.overflowY = 'scroll';
|
||
},
|
||
error: (err) => {
|
||
console.log('ERROR: ', err)
|
||
this.messageService.add({
|
||
severity: 'error',
|
||
summary: 'Произошла ошибка!',
|
||
})
|
||
}
|
||
});
|
||
this.chooseName = this.jsonRpcService.ClientChooseName;
|
||
}
|
||
|
||
changeDivision1(id: any, name: any) {
|
||
this.new_div = false;
|
||
setTimeout(() => document.getElementsByTagName("input")[0].value = name, 100);
|
||
this.jsonRpcService.changeId = id
|
||
}
|
||
|
||
changeDivision() {
|
||
let name_n = document.getElementsByTagName("input")[0].value
|
||
this.jsonRpcService.rpc2({
|
||
method: 'updateDivision',
|
||
params: {
|
||
"client_id": this.choose,
|
||
"division_id": this.jsonRpcService.changeId,
|
||
"name": name_n
|
||
}
|
||
}, RpcService.authService, false)
|
||
.subscribe({
|
||
next: (result) => {
|
||
let data = result.result;
|
||
/*this.clients = data;*/
|
||
},
|
||
error: (err) => {
|
||
console.log('ERROR: ', err)
|
||
this.messageService.add({
|
||
severity: 'error',
|
||
summary: 'Произошла ошибка!',
|
||
})
|
||
}
|
||
});
|
||
this.new_div = true;
|
||
this.jsonRpcService.changeId = "";
|
||
setTimeout(() => this.getDivisions(), 100);
|
||
}
|
||
|
||
deleteDivision(id: any) {
|
||
this.jsonRpcService.rpc2({
|
||
method: 'deleteDivision',
|
||
params: {
|
||
"client_id": this.choose,
|
||
"division_id": id
|
||
}
|
||
}, RpcService.authService, false)
|
||
.subscribe({
|
||
next: (result) => {
|
||
let data = result.result;
|
||
/*this.clients = data;*/
|
||
},
|
||
error: (err) => {
|
||
console.log('ERROR: ', err)
|
||
this.messageService.add({
|
||
severity: 'error',
|
||
summary: 'Произошла ошибка!',
|
||
})
|
||
}
|
||
});
|
||
setTimeout(() => this.getDivisions(), 100);
|
||
}
|
||
|
||
chooseClient(id: any, name: any) {
|
||
console.log(id);
|
||
this.jsonRpcService.ClientChooseName = name;
|
||
this.jsonRpcService.ClientChoose = id;
|
||
this.choose = this.jsonRpcService.ClientChoose;
|
||
this.chooseName = this.jsonRpcService.ClientChooseName;
|
||
}
|
||
|
||
createDivision() {
|
||
this.new_div = false;
|
||
this.create = true;
|
||
}
|
||
|
||
createDivision2() {
|
||
let name = document.getElementsByTagName("input")[0].value
|
||
this.jsonRpcService.rpc2({
|
||
method: 'createDivision',
|
||
params: {
|
||
"name": name,
|
||
"client_id": this.choose
|
||
}
|
||
}, RpcService.authService, false)
|
||
.subscribe({
|
||
next: (result) => {
|
||
let data = result.result;
|
||
/*this.clients = data;*/
|
||
},
|
||
error: (err) => {
|
||
console.log('ERROR: ', err)
|
||
this.messageService.add({
|
||
severity: 'error',
|
||
summary: 'Произошла ошибка!',
|
||
})
|
||
}
|
||
});
|
||
setTimeout(() => this.getDivisions(), 100);
|
||
|
||
}
|
||
|
||
confirm(id: any) {
|
||
this.confirmationService.confirm({
|
||
message: 'Вы действительно хотите удалить элемент?',
|
||
accept: () => {
|
||
this.deleteDivision(id)
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|