Replace schedule factory by schedule service.
This commit is contained in:
parent
42c0fe6c9b
commit
d52d382653
@ -34,7 +34,7 @@ var ngMessages = require('angular-messages'),
|
|||||||
ngStrap = require('angular-strap');
|
ngStrap = require('angular-strap');
|
||||||
|
|
||||||
import { ScheduleController } from './schedule.controller';
|
import { ScheduleController } from './schedule.controller';
|
||||||
import { ScheduleFactory } from './schedule.factory';
|
import { ScheduleService } from './schedule.service';
|
||||||
|
|
||||||
export default angular.module('accountant.scheduler', [
|
export default angular.module('accountant.scheduler', [
|
||||||
ngMessages,
|
ngMessages,
|
||||||
@ -47,7 +47,7 @@ export default angular.module('accountant.scheduler', [
|
|||||||
|
|
||||||
.factory('logger', downgradeInjectable(Logger))
|
.factory('logger', downgradeInjectable(Logger))
|
||||||
|
|
||||||
.factory('ScheduledOperation', ScheduleFactory)
|
.factory('scheduleService', downgradeInjectable(ScheduleService))
|
||||||
|
|
||||||
.controller('SchedulerController', ScheduleController)
|
.controller('SchedulerController', ScheduleController)
|
||||||
|
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
import { Logger } from '@nsalaun/ng-logger';
|
import { Logger } from '@nsalaun/ng-logger';
|
||||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { ToastrService } from 'ngx-toastr';
|
import { ToastrService } from 'ngx-toastr';
|
||||||
|
|
||||||
|
import { ScheduleService } from './schedule.service';
|
||||||
|
import { Schedule } from './schedule';
|
||||||
|
|
||||||
var scheduleFormTmpl = require('./schedule.form.tmpl.html'),
|
var scheduleFormTmpl = require('./schedule.form.tmpl.html'),
|
||||||
scheduleDeleteTmpl = require('./schedule.delete.tmpl.html');
|
scheduleDeleteTmpl = require('./schedule.delete.tmpl.html');
|
||||||
|
|
||||||
@ -11,41 +16,50 @@ export class ScheduleController{
|
|||||||
constructor(
|
constructor(
|
||||||
private $stateParams,
|
private $stateParams,
|
||||||
private toastrService: ToastrService,
|
private toastrService: ToastrService,
|
||||||
private ScheduledOperation,
|
private scheduleService: ScheduleService,
|
||||||
private $modal
|
private $modal
|
||||||
) {
|
) {
|
||||||
// Load operations on controller initialization.
|
// Load operations on controller initialization.
|
||||||
this.operations = this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a new operation at the beginning of th array.
|
* Add a new operation at the beginning of th array.
|
||||||
*/
|
*/
|
||||||
add = function() {
|
add = function() {
|
||||||
var operation = new this.ScheduledOperation({
|
var schedule = new Schedule();
|
||||||
account_id: this.$stateParams.accountId
|
schedule.account_id = this.$stateParams.accountId;
|
||||||
});
|
|
||||||
|
|
||||||
return this.modify(operation);
|
return this.modify(schedule);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load operations.
|
* Load operations.
|
||||||
*/
|
*/
|
||||||
load = function() {
|
load = function() {
|
||||||
return this.ScheduledOperation.query({
|
return this.scheduleService.query(this.$stateParams.accountId)
|
||||||
account_id: this.$stateParams.accountId
|
.subscribe((schedules: Schedule[]) => {
|
||||||
});
|
this.operations = schedules;
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save operation.
|
* Save operation.
|
||||||
*/
|
*/
|
||||||
save = function(operation) {
|
save = function(operation: Schedule) {
|
||||||
return operation.$save().then((operation) => {
|
let subscription: Observable<Schedule>;
|
||||||
|
|
||||||
|
if(operation.id) {
|
||||||
|
subscription = this.scheduleService.create(operation);
|
||||||
|
} else {
|
||||||
|
subscription = this.scheduleService.update(operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
return subscription.subscribe((operation: Schedule) => {
|
||||||
this.toastrService.success('Scheduled operation #' + operation.id + ' saved.');
|
this.toastrService.success('Scheduled operation #' + operation.id + ' saved.');
|
||||||
|
|
||||||
this.operations = this.load();
|
this.load();
|
||||||
|
|
||||||
return operation;
|
return operation;
|
||||||
}, (result) => {
|
}, (result) => {
|
||||||
@ -58,7 +72,7 @@ export class ScheduleController{
|
|||||||
/*
|
/*
|
||||||
* Delete an operation and return a promise.
|
* Delete an operation and return a promise.
|
||||||
*/
|
*/
|
||||||
confirmDelete = function(operation) {
|
confirmDelete = function(operation: Schedule) {
|
||||||
var title = "Delete operation #" + operation.id;
|
var title = "Delete operation #" + operation.id;
|
||||||
|
|
||||||
this.$modal({
|
this.$modal({
|
||||||
@ -84,13 +98,13 @@ export class ScheduleController{
|
|||||||
/*
|
/*
|
||||||
* Delete operation.
|
* Delete operation.
|
||||||
*/
|
*/
|
||||||
delete = function(operation) {
|
delete = function(operation: Schedule) {
|
||||||
var id = operation.id;
|
var id = operation.id;
|
||||||
|
|
||||||
return operation.$delete().then(() => {
|
return this.scheduleService.delete(operation).subscribe(() => {
|
||||||
this.toastrService.success('Scheduled operation #' + id + ' deleted.');
|
this.toastrService.success('Scheduled operation #' + id + ' deleted.');
|
||||||
|
|
||||||
this.operations = this.load();
|
this.load();
|
||||||
|
|
||||||
return operation;
|
return operation;
|
||||||
}, (result) => {
|
}, (result) => {
|
||||||
@ -105,7 +119,7 @@ export class ScheduleController{
|
|||||||
* Open the popup to modify the operation, save it on confirm.
|
* Open the popup to modify the operation, save it on confirm.
|
||||||
* @returns a promise.
|
* @returns a promise.
|
||||||
*/
|
*/
|
||||||
modify = function(operation) {
|
modify = function(operation: Schedule) {
|
||||||
// FIXME Alexis Lahouze 2017-06-15 i18n
|
// FIXME Alexis Lahouze 2017-06-15 i18n
|
||||||
var title = "Operation";
|
var title = "Operation";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user