Skip to content

Commit

Permalink
Viết hàm xử lý chức năng thay đổi status, special
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyengiangk62uet committed Apr 5, 2019
1 parent f737cf7 commit d3d3e04
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions Management/src/app/exams/list/list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,112 @@ export class ListComponent implements OnInit {
return this.sortType == 'asc' ? 'fa-sort-asc' : 'fa-sort-desc';
return '';
}

changeStatus(id, status) {
this.ngProgress.start();
this.loading = true;
const objExam: any = {
status: status,
modified: {
user_id: 'admin',
user_name: 'admin',
time: Date.now()
}
};
this._examService.changeStatus(id, objExam)
.subscribe(
data => {
this.pagedItems.map((exam, i) => {
if (exam._id === id) {
const newStatus = this.pagedItems[i].status === 'active' ? 'inactive' : 'active';
this.pagedItems[i].status = newStatus;
}
});
},
error => this.reloadPageIfError(),
() => {
this.ngProgress.done();
this.loading = false;
});
}

changeSpecial(id, special) {
this.ngProgress.start();
this.loading = true;
const objExam: any = {
special: special,
modified: {
user_id: 'admin',
user_name: 'admin',
time: Date.now()
}
};
this._examService.changeSpecial(id, objExam)
.subscribe(
data => {
this.pagedItems.map((exam, i) => {
if (exam._id === id) {
const newSpecial = this.pagedItems[i].special === 'active' ? 'inactive' : 'active';
this.pagedItems[i].special = newSpecial;
}
});
},
error => this.reloadPageIfError(),
() => {
this.ngProgress.done();
this.loading = false;
});
}

/*--------------------------------------------*/
clickOnChangeMulti(prop, state) {
let arrIdUbdate = [];
this.pagedItems.forEach((item) => {
if (item.selected) {
arrIdUbdate.push(item._id);
}
});

if (arrIdUbdate.length === 0) {
showAlert('warning', 'Please choosen an exam', 'Click to back in list',
false, 'btn btn-warning');
} else {
this.ngProgress.start();
this.loading = true;
const objUpdate: any = {
action: state,
items: arrIdUbdate,
modified: {
user_id: 'admin',
user_name: 'admin',
time: Date.now()
}
};
this._examService.changeMultiOnClick(objUpdate, prop)
.subscribe(
data => {
this.allItems.map(item => {
if (prop === 'status' && item.selected)
item.status = state;
if (prop === 'special' && item.selected)
item.special = state;
item.selected = false;
});
},
error => this.reloadPageIfError(),
() => {
this.ngProgress.done();
this.loading = false;
this.selectAll = false;
});
}
}

/*---------------------------------------------------*/

checkAllExams() {
this.allItems.forEach(item => {
item.selected = this.selectAll;
});
}
}

0 comments on commit d3d3e04

Please sign in to comment.