2017-08-01 23:22:44 +02:00
|
|
|
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
2017-07-25 12:03:42 +02:00
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
2017-08-01 23:09:21 +02:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
2017-07-22 11:16:04 +02:00
|
|
|
import { Observable } from 'rxjs/Rx';
|
|
|
|
|
2017-07-22 09:17:50 +02:00
|
|
|
import { Logger } from '@nsalaun/ng-logger';
|
|
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
|
|
|
import { ToastrService } from 'ngx-toastr';
|
|
|
|
|
2017-07-25 17:25:50 +02:00
|
|
|
import { ScheduleEditModalComponent } from './scheduleEditModal.component';
|
2017-07-22 11:16:04 +02:00
|
|
|
import { ScheduleService } from './schedule.service';
|
|
|
|
import { Schedule } from './schedule';
|
|
|
|
|
2017-07-25 12:03:42 +02:00
|
|
|
@Component({
|
2017-08-01 23:22:44 +02:00
|
|
|
selector: 'schedule-list',
|
|
|
|
template: `
|
2017-07-25 12:03:42 +02:00
|
|
|
<div class="row">
|
2017-07-25 22:11:16 +02:00
|
|
|
<table class="table table-sm table-striped table-condensed table-hover">
|
2017-07-25 12:03:42 +02:00
|
|
|
<thead>
|
|
|
|
<tr>
|
2017-07-25 22:11:16 +02:00
|
|
|
<th>Date de début</th>
|
|
|
|
<th>Date de fin</th>
|
|
|
|
<th>Jour</th>
|
|
|
|
<th>Fréq.</th>
|
2017-07-25 12:03:42 +02:00
|
|
|
<th>Libellé de l'opération</th>
|
2017-07-25 22:11:16 +02:00
|
|
|
<th>Montant</th>
|
|
|
|
<th>Catégorie</th>
|
|
|
|
<th>Actions</th>
|
2017-07-25 12:03:42 +02:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td colspan="8">
|
|
|
|
<button class="btn btn-success" (click)="add()">
|
|
|
|
Ajouter
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<tr *ngFor="let schedule of schedules"
|
|
|
|
[schedule-row]="schedule" (needsReload)="load()">
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
2017-07-25 16:56:57 +02:00
|
|
|
export class ScheduleListComponent implements OnInit {
|
2017-08-01 23:22:44 +02:00
|
|
|
accountId: number;
|
|
|
|
schedules = [];
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private toastrService: ToastrService,
|
|
|
|
private scheduleService: ScheduleService,
|
|
|
|
private logger: Logger,
|
|
|
|
private ngbModal: NgbModal,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.logger.log("ngOnInit");
|
|
|
|
this.accountId = +this.route.snapshot.paramMap.get('accountId')
|
|
|
|
// Load operations on controller initialization.
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new operation at the beginning of th array.
|
|
|
|
*/
|
|
|
|
add() {
|
|
|
|
var schedule = new Schedule();
|
|
|
|
schedule.account_id = this.accountId;
|
|
|
|
|
2017-08-11 22:24:09 +02:00
|
|
|
const modal = this.ngbModal.open(ScheduleEditModalComponent, {
|
|
|
|
size: 'lg'
|
|
|
|
});
|
2017-08-01 23:22:44 +02:00
|
|
|
|
|
|
|
modal.componentInstance.schedule = schedule;
|
|
|
|
|
|
|
|
modal.result.then((schedule: Schedule) => {
|
|
|
|
this.save(schedule);
|
|
|
|
}, (reason) => function(reason) {
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
load() {
|
|
|
|
this.logger.log("Loading schedules for accountId", this.accountId);
|
|
|
|
if(!this.accountId) {
|
|
|
|
return;
|
2017-07-25 12:03:42 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 23:22:44 +02:00
|
|
|
this.scheduleService.query(this.accountId)
|
|
|
|
.subscribe((schedules: Schedule[]) => {
|
|
|
|
this.logger.log("Schedules loaded.", schedules);
|
|
|
|
this.schedules = schedules;
|
|
|
|
}, (reason) => {
|
|
|
|
this.logger.log("Got error", reason);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
save(schedule: Schedule) {
|
|
|
|
return this.scheduleService.create(schedule).subscribe((schedule: Schedule) => {
|
|
|
|
this.toastrService.success('Schedule #' + schedule.id + ' saved.');
|
|
|
|
|
|
|
|
this.load();
|
|
|
|
}, (result) => {
|
|
|
|
this.toastrService.error(
|
|
|
|
'Error while saving schedule: ' + result.message
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
2017-07-08 12:20:17 +02:00
|
|
|
};
|