|
@@ -2,7 +2,7 @@ import {Component, OnInit} from '@angular/core';
|
|
import {ICollection, Resource, Service} from 'ngx-jsonapi';
|
|
import {ICollection, Resource, Service} from 'ngx-jsonapi';
|
|
import {MatDialogConfig} from '@angular/material';
|
|
import {MatDialogConfig} from '@angular/material';
|
|
import {DialogComponent} from '../dialog/dialog.component';
|
|
import {DialogComponent} from '../dialog/dialog.component';
|
|
-import {Dialog} from '../../dialog';
|
|
|
|
|
|
+import {Dialog} from '../dialog/dialog';
|
|
import {EditComponent} from '../edit/edit.component';
|
|
import {EditComponent} from '../edit/edit.component';
|
|
import {IParamsResource} from 'ngx-jsonapi/interfaces';
|
|
import {IParamsResource} from 'ngx-jsonapi/interfaces';
|
|
import {Headers, Http} from '@angular/http';
|
|
import {Headers, Http} from '@angular/http';
|
|
@@ -10,7 +10,6 @@ import {Observable} from 'rxjs/Observable';
|
|
import {CookieService} from 'ngx-cookie-service';
|
|
import {CookieService} from 'ngx-cookie-service';
|
|
import {environment} from '../../../../environments/environment';
|
|
import {environment} from '../../../../environments/environment';
|
|
|
|
|
|
-
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'app-list',
|
|
selector: 'app-list',
|
|
template: '',
|
|
template: '',
|
|
@@ -38,13 +37,13 @@ export class ListComponent implements OnInit {
|
|
sortProp = 'id';
|
|
sortProp = 'id';
|
|
sortDir = 'asc';
|
|
sortDir = 'asc';
|
|
count = 0;
|
|
count = 0;
|
|
- limit = 4;
|
|
|
|
|
|
+ limit = 10;
|
|
offset = 0;
|
|
offset = 0;
|
|
is_loading = false;
|
|
is_loading = false;
|
|
filters = {};
|
|
filters = {};
|
|
filteredOptions = [];
|
|
filteredOptions = [];
|
|
lists;
|
|
lists;
|
|
- appUrl : any;
|
|
|
|
|
|
+ appUrl: any;
|
|
includes;
|
|
includes;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -53,10 +52,10 @@ export class ListComponent implements OnInit {
|
|
* @param {Dialog} dialog baray baz kardan dialog
|
|
* @param {Dialog} dialog baray baz kardan dialog
|
|
* @param {EditComponent} editComponent ye component pedar baray ers barie dialog
|
|
* @param {EditComponent} editComponent ye component pedar baray ers barie dialog
|
|
*/
|
|
*/
|
|
- constructor(protected listService: Service,
|
|
|
|
- protected dialog: Dialog,
|
|
|
|
- protected editComponent: EditComponent,
|
|
|
|
- protected http: Http,
|
|
|
|
|
|
+ constructor(public listService: Service,
|
|
|
|
+ public dialog: Dialog,
|
|
|
|
+ public editComponent: EditComponent,
|
|
|
|
+ public http: Http,
|
|
) {
|
|
) {
|
|
this.appUrl = environment.app_url;
|
|
this.appUrl = environment.app_url;
|
|
}
|
|
}
|
|
@@ -69,10 +68,11 @@ export class ListComponent implements OnInit {
|
|
this.fetchList('null');
|
|
this.fetchList('null');
|
|
// set columns from server
|
|
// set columns from server
|
|
let cols = JSON.parse(localStorage.getItem('columns'));
|
|
let cols = JSON.parse(localStorage.getItem('columns'));
|
|
- if (cols[window.location.pathname])
|
|
|
|
|
|
+ if (cols[window.location.pathname]) {
|
|
cols = cols[window.location.pathname].toString();
|
|
cols = cols[window.location.pathname].toString();
|
|
- else
|
|
|
|
|
|
+ } else {
|
|
cols = '';
|
|
cols = '';
|
|
|
|
+ }
|
|
cols = cols.split(',');
|
|
cols = cols.split(',');
|
|
// column haei ro bede ke too cols array bashe
|
|
// column haei ro bede ke too cols array bashe
|
|
if (cols[0] != '') {
|
|
if (cols[0] != '') {
|
|
@@ -94,14 +94,18 @@ export class ListComponent implements OnInit {
|
|
this.sortDir = event.sorts[0].dir;
|
|
this.sortDir = event.sorts[0].dir;
|
|
this.setDefaultNumberts();
|
|
this.setDefaultNumberts();
|
|
}
|
|
}
|
|
- if (event.hasOwnProperty('count'))
|
|
|
|
|
|
+ if (event.hasOwnProperty('count')) {
|
|
this.count = event.count;
|
|
this.count = event.count;
|
|
- if (event.hasOwnProperty('limit'))
|
|
|
|
|
|
+ }
|
|
|
|
+ if (event.hasOwnProperty('limit')) {
|
|
this.limit = event.limit;
|
|
this.limit = event.limit;
|
|
- if (event.hasOwnProperty('offset'))
|
|
|
|
|
|
+ }
|
|
|
|
+ if (event.hasOwnProperty('offset')) {
|
|
this.offset = event.offset;
|
|
this.offset = event.offset;
|
|
- if (event == 'filter')
|
|
|
|
|
|
+ }
|
|
|
|
+ if (event == 'filter') {
|
|
this.setDefaultNumberts();
|
|
this.setDefaultNumberts();
|
|
|
|
+ }
|
|
if (event == 'refresh') {
|
|
if (event == 'refresh') {
|
|
this.setDefaultSorts();
|
|
this.setDefaultSorts();
|
|
this.setDefaultFilters();
|
|
this.setDefaultFilters();
|
|
@@ -110,9 +114,9 @@ export class ListComponent implements OnInit {
|
|
this.includes = [];
|
|
this.includes = [];
|
|
let that = this;
|
|
let that = this;
|
|
for (let key in this.columns) {
|
|
for (let key in this.columns) {
|
|
- if (this.columns[key].mustIncluded)
|
|
|
|
-
|
|
|
|
|
|
+ if (this.columns[key].mustIncluded) {
|
|
that.includes.push(this.columns[key].prop);
|
|
that.includes.push(this.columns[key].prop);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
this.listService.all(
|
|
this.listService.all(
|
|
{
|
|
{
|
|
@@ -122,22 +126,22 @@ export class ListComponent implements OnInit {
|
|
include: that.includes
|
|
include: that.includes
|
|
}
|
|
}
|
|
).subscribe(lists => {
|
|
).subscribe(lists => {
|
|
- if (lists.$source != 'server' || lists.$is_loading)
|
|
|
|
|
|
+ if (lists.$source != 'server' || lists.$is_loading) {
|
|
return;
|
|
return;
|
|
|
|
+ }
|
|
this.rows = [];
|
|
this.rows = [];
|
|
- let listsArray = lists.$toArray;
|
|
|
|
|
|
+ let listsArray = lists.$toArray;
|
|
let page: any = lists.page.number;
|
|
let page: any = lists.page.number;
|
|
-
|
|
|
|
this.count = page.total;
|
|
this.count = page.total;
|
|
this.limit = page['per-page'];
|
|
this.limit = page['per-page'];
|
|
this.offset = page['current-page'] - 1;
|
|
this.offset = page['current-page'] - 1;
|
|
for (let list_key in listsArray) {
|
|
for (let list_key in listsArray) {
|
|
let row = [];
|
|
let row = [];
|
|
|
|
+ row['id'] = listsArray[list_key].id;
|
|
for (let key in this.columns) {
|
|
for (let key in this.columns) {
|
|
let prop = this.columns[key].prop;
|
|
let prop = this.columns[key].prop;
|
|
- if (prop == 'id')
|
|
|
|
- row['id'] = listsArray[list_key].id;
|
|
|
|
- else if (this.columns[key].replaceFunc) {
|
|
|
|
|
|
+ if (prop == 'id') {
|
|
|
|
+ } else if (this.columns[key].replaceFunc) {
|
|
row[prop] = this.columns[key].replaceFunc(listsArray[list_key].attributes[prop]);
|
|
row[prop] = this.columns[key].replaceFunc(listsArray[list_key].attributes[prop]);
|
|
} else {
|
|
} else {
|
|
if (this.columns[key].isRelationship) {
|
|
if (this.columns[key].isRelationship) {
|
|
@@ -167,17 +171,21 @@ export class ListComponent implements OnInit {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
row[prop] = (names.join(',')).substr(0, 10) + '...';
|
|
row[prop] = (names.join(',')).substr(0, 10) + '...';
|
|
- } else
|
|
|
|
|
|
+ } else {
|
|
row[prop] = '';
|
|
row[prop] = '';
|
|
- } else
|
|
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
row[prop] = listsArray[list_key].attributes[prop];
|
|
row[prop] = listsArray[list_key].attributes[prop];
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let exists = false;
|
|
let exists = false;
|
|
|
|
+
|
|
for (let key in this.rows) {
|
|
for (let key in this.rows) {
|
|
- if (this.rows[key]['id'] == row['id'])
|
|
|
|
|
|
+ if (this.rows[key]['id'] == row['id']) {
|
|
exists = true;
|
|
exists = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if (!exists) {
|
|
if (!exists) {
|
|
this.rows.push(row);
|
|
this.rows.push(row);
|
|
@@ -185,6 +193,7 @@ export class ListComponent implements OnInit {
|
|
|
|
|
|
}
|
|
}
|
|
this.lists = lists;
|
|
this.lists = lists;
|
|
|
|
+
|
|
}, error => {
|
|
}, error => {
|
|
console.log(error);
|
|
console.log(error);
|
|
}, () => {
|
|
}, () => {
|
|
@@ -225,8 +234,9 @@ export class ListComponent implements OnInit {
|
|
for (var key in filters) {
|
|
for (var key in filters) {
|
|
if (Array.isArray(filters[key])) {
|
|
if (Array.isArray(filters[key])) {
|
|
ret[key] = filters[key].join(',');
|
|
ret[key] = filters[key].join(',');
|
|
- } else
|
|
|
|
|
|
+ } else {
|
|
ret[key] = filters[key];
|
|
ret[key] = filters[key];
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
@@ -241,15 +251,13 @@ export class ListComponent implements OnInit {
|
|
dialogConfig.disableClose = true;
|
|
dialogConfig.disableClose = true;
|
|
dialogConfig.autoFocus = true;
|
|
dialogConfig.autoFocus = true;
|
|
dialogConfig.data = {
|
|
dialogConfig.data = {
|
|
- message: 'این کاربر حذف خواهد شد .' +
|
|
|
|
- 'آیا مطمئن هستید؟',
|
|
|
|
|
|
+ message: 'آیا مطمئن هستید؟',
|
|
type: 'yesno'
|
|
type: 'yesno'
|
|
};
|
|
};
|
|
|
|
|
|
const dialogRef = this.dialog.open(DialogComponent, dialogConfig);
|
|
const dialogRef = this.dialog.open(DialogComponent, dialogConfig);
|
|
dialogRef.afterClosed().subscribe(
|
|
dialogRef.afterClosed().subscribe(
|
|
result => {
|
|
result => {
|
|
-
|
|
|
|
if (result) {
|
|
if (result) {
|
|
this.listService.delete(id).subscribe(ok => {
|
|
this.listService.delete(id).subscribe(ok => {
|
|
this.fetchList(null);
|
|
this.fetchList(null);
|
|
@@ -270,7 +278,7 @@ export class ListComponent implements OnInit {
|
|
|
|
|
|
if (!id) {
|
|
if (!id) {
|
|
const resource = this.listService.new();
|
|
const resource = this.listService.new();
|
|
- // let requiredPermission = this.listService.type + '.create';
|
|
|
|
|
|
+ // let requiredPermission = this.listService.requestType + '.create';
|
|
// if(hasAccess(requiredPermission))
|
|
// if(hasAccess(requiredPermission))
|
|
// {
|
|
// {
|
|
const dialogRef = this.dialog.openWithData(this.editComponent, resource);
|
|
const dialogRef = this.dialog.openWithData(this.editComponent, resource);
|
|
@@ -287,7 +295,7 @@ export class ListComponent implements OnInit {
|
|
|
|
|
|
} else {
|
|
} else {
|
|
// {
|
|
// {
|
|
- // let requiredPermission = this.listService.type + '.update';
|
|
|
|
|
|
+ // let requiredPermission = this.listService.requestType + '.update';
|
|
// if (hasAccess(requiredPermission)) {
|
|
// if (hasAccess(requiredPermission)) {
|
|
this.listService.get(id, params)
|
|
this.listService.get(id, params)
|
|
.subscribe(
|
|
.subscribe(
|
|
@@ -324,8 +332,9 @@ export class ListComponent implements OnInit {
|
|
remotefilter: remoteFilter,
|
|
remotefilter: remoteFilter,
|
|
page: {number: 1, size: 5}
|
|
page: {number: 1, size: 5}
|
|
}).subscribe(data => {
|
|
}).subscribe(data => {
|
|
- if (data.$source != 'server' || data.$is_loading)
|
|
|
|
|
|
+ if (data.$source != 'server' || data.$is_loading) {
|
|
return;
|
|
return;
|
|
|
|
+ }
|
|
this.filteredOptions[prop] = data.$toArray;
|
|
this.filteredOptions[prop] = data.$toArray;
|
|
|
|
|
|
});
|
|
});
|
|
@@ -337,45 +346,36 @@ export class ListComponent implements OnInit {
|
|
* @param value مقداری که قراره فیلتر کنیم
|
|
* @param value مقداری که قراره فیلتر کنیم
|
|
*/
|
|
*/
|
|
protected setFiltersVarAndRefresh(key, value) {
|
|
protected setFiltersVarAndRefresh(key, value) {
|
|
-
|
|
|
|
this.filters[key] = value;
|
|
this.filters[key] = value;
|
|
this.fetchList('filter');
|
|
this.fetchList('filter');
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
toggle(col): Observable<boolean> {
|
|
toggle(col): Observable<boolean> {
|
|
const isChecked = this.isChecked(col);
|
|
const isChecked = this.isChecked(col);
|
|
if (isChecked) {
|
|
if (isChecked) {
|
|
- if (this.columns.length < 2 || col.prop == 'id')
|
|
|
|
|
|
+ if (this.columns.length < 2 || col.prop == 'id') {
|
|
return;
|
|
return;
|
|
|
|
+ }
|
|
this.columns = this.columns.filter(c => {
|
|
this.columns = this.columns.filter(c => {
|
|
return c.prop !== col.prop;
|
|
return c.prop !== col.prop;
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
- this.columns = [...this.columns, col];
|
|
|
|
|
|
+ this.columns = [col , ...this.columns];
|
|
}
|
|
}
|
|
// sort ba asase all columns
|
|
// sort ba asase all columns
|
|
- this.columns = this.allColumns.filter(c => {
|
|
|
|
|
|
+ this.columns = this.columns.filter(c => {
|
|
return this.columns.find(c2 => {
|
|
return this.columns.find(c2 => {
|
|
return c.prop === c2.prop;
|
|
return c.prop === c2.prop;
|
|
});
|
|
});
|
|
});
|
|
});
|
|
-
|
|
|
|
-
|
|
|
|
let cols = [];
|
|
let cols = [];
|
|
for (let key in this.columns) {
|
|
for (let key in this.columns) {
|
|
cols.push(this.columns[key]['prop']);
|
|
cols.push(this.columns[key]['prop']);
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
this.setColumns(cols).subscribe(result => {
|
|
this.setColumns(cols).subscribe(result => {
|
|
-
|
|
|
|
-
|
|
|
|
this.fetchList('null');
|
|
this.fetchList('null');
|
|
}, error1 => {
|
|
}, error1 => {
|
|
});
|
|
});
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
isChecked(col) {
|
|
isChecked(col) {
|