Migrate schedule list to material.
This commit is contained in:
parent
048a2a7d08
commit
f632722916
@ -3,6 +3,14 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
|
import {
|
||||||
|
MdButtonModule,
|
||||||
|
MdDialogModule,
|
||||||
|
MdIconModule,
|
||||||
|
MdInputModule,
|
||||||
|
MdListModule,
|
||||||
|
MdTableModule,
|
||||||
|
} from '@angular/material';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
import { RouterModule } from '@angular/router';
|
import { RouterModule } from '@angular/router';
|
||||||
|
|
||||||
@ -16,7 +24,6 @@ import { ScheduleDataSource } from './schedule.dataSource';
|
|||||||
import { ScheduleDeleteModalComponent } from './scheduleDeleteModal.component';
|
import { ScheduleDeleteModalComponent } from './scheduleDeleteModal.component';
|
||||||
import { ScheduleEditModalComponent } from './scheduleEditModal.component';
|
import { ScheduleEditModalComponent } from './scheduleEditModal.component';
|
||||||
import { ScheduleFormComponent } from './scheduleForm.component';
|
import { ScheduleFormComponent } from './scheduleForm.component';
|
||||||
import { ScheduleRowComponent } from './scheduleRow.component';
|
|
||||||
import { ScheduleListComponent } from './scheduleList.component';
|
import { ScheduleListComponent } from './scheduleList.component';
|
||||||
import { ScheduleListState } from './schedule.states';
|
import { ScheduleListState } from './schedule.states';
|
||||||
|
|
||||||
@ -28,6 +35,12 @@ import { ScheduleListState } from './schedule.states';
|
|||||||
RouterModule.forChild([
|
RouterModule.forChild([
|
||||||
ScheduleListState
|
ScheduleListState
|
||||||
]),
|
]),
|
||||||
|
MdButtonModule,
|
||||||
|
MdDialogModule,
|
||||||
|
MdIconModule,
|
||||||
|
MdInputModule,
|
||||||
|
MdListModule,
|
||||||
|
MdTableModule,
|
||||||
NgLoggerModule,
|
NgLoggerModule,
|
||||||
ToastrModule,
|
ToastrModule,
|
||||||
NgbModule,
|
NgbModule,
|
||||||
@ -42,7 +55,6 @@ import { ScheduleListState } from './schedule.states';
|
|||||||
ScheduleEditModalComponent,
|
ScheduleEditModalComponent,
|
||||||
ScheduleFormComponent,
|
ScheduleFormComponent,
|
||||||
ScheduleListComponent,
|
ScheduleListComponent,
|
||||||
ScheduleRowComponent
|
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
ScheduleDeleteModalComponent,
|
ScheduleDeleteModalComponent,
|
||||||
|
@ -8,6 +8,8 @@ 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 { ScheduleDataSource } from './schedule.dataSource';
|
||||||
|
import { ScheduleDeleteModalComponent } from './scheduleDeleteModal.component';
|
||||||
import { ScheduleEditModalComponent } from './scheduleEditModal.component';
|
import { ScheduleEditModalComponent } from './scheduleEditModal.component';
|
||||||
import { ScheduleService } from './schedule.service';
|
import { ScheduleService } from './schedule.service';
|
||||||
import { Schedule } from './schedule';
|
import { Schedule } from './schedule';
|
||||||
@ -15,41 +17,95 @@ import { Schedule } from './schedule';
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'schedule-list',
|
selector: 'schedule-list',
|
||||||
template: `
|
template: `
|
||||||
<div class="row">
|
<div class="containerX">
|
||||||
<table class="table table-sm table-striped table-condensed table-hover">
|
<div class="container">
|
||||||
<thead>
|
<button md-fab color="primary" (click)="add()">
|
||||||
<tr>
|
<md-icon>add</md-icon>
|
||||||
<th>Date de début</th>
|
</button>
|
||||||
<th>Date de fin</th>
|
</div>
|
||||||
<th>Jour</th>
|
|
||||||
<th>Fréq.</th>
|
|
||||||
<th>Libellé de l'opération</th>
|
|
||||||
<th>Montant</th>
|
|
||||||
<th>Catégorie</th>
|
|
||||||
<th>Actions</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
|
|
||||||
<tbody>
|
<div class="container">
|
||||||
<tr>
|
<md-table #table [dataSource]="schedules">
|
||||||
<td colspan="8">
|
<ng-container mdColumnDef="start_date">
|
||||||
<button class="btn btn-success" (click)="add()">
|
<md-header-cell *mdHeaderCellDef>Date de début</md-header-cell>
|
||||||
Ajouter
|
<md-cell *mdCellDef="let schedule">
|
||||||
|
{{ schedule.start_date | date: "yyyy-MM-dd" }}
|
||||||
|
</md-cell>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container mdColumnDef="stop_date">
|
||||||
|
<md-header-cell *mdHeaderCellDef>Date de fin</md-header-cell>
|
||||||
|
<md-cell *mdCellDef="let schedule">
|
||||||
|
{{ schedule.stop_date | date: "yyyy-MM-dd" }}
|
||||||
|
</md-cell>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container mdColumnDef="day">
|
||||||
|
<md-header-cell *mdHeaderCellDef>Jour</md-header-cell>
|
||||||
|
<md-cell *mdCellDef="let schedule">
|
||||||
|
{{ schedule.day }}
|
||||||
|
</md-cell>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container mdColumnDef="frequency">
|
||||||
|
<md-header-cell *mdHeaderCellDef>Fréq.</md-header-cell>
|
||||||
|
<md-cell *mdCellDef="let schedule">
|
||||||
|
{{ schedule.frequency }}
|
||||||
|
</md-cell>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container mdColumnDef="label">
|
||||||
|
<md-header-cell *mdHeaderCellDef>Libellé de l'opération</md-header-cell>
|
||||||
|
<md-cell *mdCellDef="let schedule">
|
||||||
|
{{ schedule.label }}
|
||||||
|
</md-cell>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container mdColumnDef="value">
|
||||||
|
<md-header-cell *mdHeaderCellDef>Montant</md-header-cell>
|
||||||
|
<md-cell *mdCellDef="let schedule">
|
||||||
|
{{ schedule.value | currency: "EUR":true }}
|
||||||
|
</md-cell>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container mdColumnDef="category">
|
||||||
|
<md-header-cell *mdHeaderCellDef>Catégorie</md-header-cell>
|
||||||
|
<md-cell *mdCellDef="let schedule">
|
||||||
|
{{ schedule.category }}
|
||||||
|
</md-cell>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container mdColumnDef="actions">
|
||||||
|
<md-header-cell *mdHeaderCellDef>Actions</md-header-cell>
|
||||||
|
<md-cell *mdCellDef="let schedule">
|
||||||
|
<!-- Edit operation. -->
|
||||||
|
<button md-mini-fab color="primary" (click)="modify(schedule)">
|
||||||
|
<md-icon>mode_edit</md-icon>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr *ngFor="let schedule of schedules"
|
<!-- Remove operation. -->
|
||||||
[schedule-row]="schedule" (needsReload)="load()">
|
<button md-mini-fab color="warn" [hidden]="!schedule.id"
|
||||||
</tr>
|
(click)="confirmDelete(schedule)">
|
||||||
</tbody>
|
<md-icon>delete_forever</md-icon>
|
||||||
</table>
|
</button>
|
||||||
|
</md-cell>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<md-header-row *mdHeaderRowDef="displayedColumns"></md-header-row>
|
||||||
|
<md-row *mdRowDef="let row; columns: displayedColumns;">
|
||||||
|
</md-row>
|
||||||
|
</md-table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class ScheduleListComponent implements OnInit {
|
export class ScheduleListComponent implements OnInit {
|
||||||
accountId: number;
|
private accountId: number;
|
||||||
schedules = [];
|
|
||||||
|
private displayedColumns: String[] = [
|
||||||
|
'start_date', 'stop_date', 'day', 'frequency',
|
||||||
|
'label', 'value', 'category', 'actions'
|
||||||
|
];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private toastrService: ToastrService,
|
private toastrService: ToastrService,
|
||||||
@ -57,6 +113,7 @@ export class ScheduleListComponent implements OnInit {
|
|||||||
private logger: Logger,
|
private logger: Logger,
|
||||||
private ngbModal: NgbModal,
|
private ngbModal: NgbModal,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
private schedules: ScheduleDataSource,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -66,13 +123,23 @@ export class ScheduleListComponent implements OnInit {
|
|||||||
this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load() {
|
||||||
|
this.logger.log("Loading schedules for accountId", this.accountId);
|
||||||
|
if(!this.accountId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.schedules.load(this.accountId);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a new operation at the beginning of th array.
|
* Add a new operation at the beginning of th array.
|
||||||
*/
|
*/
|
||||||
add() {
|
add() {
|
||||||
var schedule = new Schedule();
|
this.modify(new Schedule());
|
||||||
schedule.account_id = this.accountId;
|
};
|
||||||
|
|
||||||
|
modify(schedule: Schedule) {
|
||||||
const modal = this.ngbModal.open(ScheduleEditModalComponent, {
|
const modal = this.ngbModal.open(ScheduleEditModalComponent, {
|
||||||
size: 'lg'
|
size: 'lg'
|
||||||
});
|
});
|
||||||
@ -83,23 +150,7 @@ export class ScheduleListComponent implements OnInit {
|
|||||||
this.save(schedule);
|
this.save(schedule);
|
||||||
}, (reason) => function(reason) {
|
}, (reason) => function(reason) {
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
load() {
|
|
||||||
this.logger.log("Loading schedules for accountId", this.accountId);
|
|
||||||
if(!this.accountId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
save(schedule: Schedule) {
|
||||||
return this.scheduleService.create(schedule).subscribe((schedule: Schedule) => {
|
return this.scheduleService.create(schedule).subscribe((schedule: Schedule) => {
|
||||||
@ -112,4 +163,30 @@ export class ScheduleListComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
confirmDelete(schedule: Schedule) {
|
||||||
|
const modal = this.ngbModal.open(ScheduleDeleteModalComponent);
|
||||||
|
|
||||||
|
modal.componentInstance.schedule = schedule;
|
||||||
|
|
||||||
|
modal.result.then((schedule: Schedule) => {
|
||||||
|
this.delete(schedule);
|
||||||
|
}, (reason) => function(reason) {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(schedule: Schedule) {
|
||||||
|
var id = schedule.id;
|
||||||
|
|
||||||
|
return this.scheduleService.delete(schedule).subscribe(() => {
|
||||||
|
this.toastrService.success('Schedule #' + id + ' deleted.');
|
||||||
|
|
||||||
|
this.load();
|
||||||
|
}, result => {
|
||||||
|
this.toastrService.error(
|
||||||
|
'An error occurred while trying to delete schedule #' + id + ':<br />'
|
||||||
|
+ result.message
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user