You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

218 lines
5.6 KiB

import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { DialogComponent } from '../dialog/dialog.component';
import { Rayconnect } from '../../../../services/rayconnect/rayconnect.service';
import * as moment from 'jalali-moment';
import { Chart } from 'chart.js'
import { FormControl } from '@angular/forms';
interface University {
value: string;
viewValue: string;
}
interface UniversityGroup {
disabled?: boolean;
name: string;
value: string;
universities: University[];
}
@Component({
selector: 'app-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
universityControl = new FormControl();
univeristygroups: UniversityGroup[] = [
{
name: 'تهران',
value: "tehran",
universities: [
{ value: 'ps1', viewValue: 'مرکز پسران ۱' },
{ value: 'ps2', viewValue: 'مرکز پسران ۲' },
]
},
{
name: 'مرکزی',
value: "markazi",
universities: [
{ value: 'athar', viewValue: 'اطهر' },
{ value: 'amirkabir', viewValue: 'امیر کبیر' },
{ value: 'khomein', viewValue: 'دکتر حسابی خمین' },
{ value: 'saveh', viewValue: 'مرکز پسران ساوه' }
]
}
];
public list: { _id: string, name: string }[] = [];
options = {
responsive: true,
}
data: any = [{
labels: ['داوطلبین', 'در مرحله تایید کارشناس', 'تایید شده', 'مرحله خوابگاه', 'اتمام ثبت نام', 'اشکال در ثبت نام'],
type: "bar",
datasets: [{
label: 'آمار کاربران کاتب',
data: [40, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.9)',
'rgba(54, 162, 235, 0.9)',
'rgba(255, 206, 86, 0.9)',
'rgba(75, 192, 192, 0.9)',
'rgba(153, 102, 255, 0.9)',
'rgba(255, 159, 64, 0.9)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
}];
constructor(private dialog: MatDialog, private rayconnect: Rayconnect, private snackbar: MatSnackBar) { }
ngOnInit(): void {
this.fetch();
Chart.defaults.global.defaultFontFamily = "Font"
this.universityControl.setValue("all")
}
RandomColor(len) {
let colors = []
for (let i = 0; i < len; i++) {
colors.push('#' + (0x1000000 + (Math.random()) * 0xffffff).toString(16).substr(1, 6)
)
}
return colors
}
buildMajorsStats(majors) {
this.data[1] = {
labels: majors.map((major) => {
return major.name
}),
type: "doughnut",
datasets: [{
label: 'تعداد ثبت نام تایید شده در مرحله پنجم (آموزش)',
data: [40, 19, 3, 5, 2, 3, 8],
backgroundColor: this.RandomColor(majors.length),
borderWidth: 1
}]
}
this.data[2] = {
labels: majors.map((major) => {
return major.name
}),
type: "doughnut",
datasets: [{
label: 'تعداد ثبت نام در انتظار تایید در مرحله پنجم (آموزش)',
data: [5, 3, 3, 5, 2, 3, 1],
backgroundColor: this.RandomColor(majors.length),
borderWidth: 1
}]
}
this.data[3] = {
labels: majors.map((major) => {
return major.name
}),
type: "doughnut",
datasets: [{
label: 'آمار مراجعات حضوری بر اساس رشته',
data: [5, 3, 3, 5, 2, 3, 1],
backgroundColor: this.RandomColor(majors.length),
borderWidth: 1
}]
}
let labels = []
let m = moment()
for (let index = 0; index < 10; index++) {
m = m.add(1, 'd')
labels.push(m.format('jYYYY/jM/jD'));
}
this.data[4] = {
labels: labels,
type: "line",
datasets: [{
label: 'آمار مراجعات حضوری بر اساس تاریخ',
data: labels.map((da) => {
return Math.floor(Math.random() * 6);
}),
borderColor: 'rgb(75, 192, 192)',
lineTension: 0.1,
borderWidth: 1
}]
}
}
fetch() {
this.rayconnect.RequestBack({
scope: 'kateb',
uniqueID: 'profile',
TokenID: '*',
address: 'major/list',
info: {
method: 'LIST',
data: {}
}
}).then(res => {
if (res['data']['status'] == true) this.buildMajorsStats(res['data']['result'])
})
}
delete(id: string) {
this.rayconnect.RequestBack({
scope: 'kateb',
uniqueID: 'profile',
TokenID: '*',
address: 'major/delete',
info: {
method: 'DELETE',
data: { id }
}
}).then(res => {
this.snackbar.open(res['data']['message'], 'باشه', { duration: 3000, direction: 'rtl' });
if (res['data']['status'] == true) {
let index = this.list.findIndex(item => item._id == id);
this.list.splice(index, 1);
}
})
}
openDialog(data) {
this.dialog.open(DialogComponent, { data, autoFocus: false, disableClose: true }).afterClosed().subscribe((result: { name: string, _id: string }) => {
if (!result) return;
let index = this.list.findIndex(item => item._id == result._id);
if (index < 0) this.list.push(result);
else this.list[index] = result;
})
}
}