Use component in scheduler route, inject accountId into.

This commit is contained in:
Alexis Lahouze 2017-07-23 00:12:44 +02:00
parent 3326dac51a
commit c4c10f9ab7
3 changed files with 24 additions and 9 deletions

View File

@ -2,7 +2,6 @@
import { Level } from '@nsalaun/ng-logger';
var operationsTmpl = require('./operations/operations.html');
var schedulerTmpl = require('./scheduler/scheduler.html');
export default function AppConfig($uiRouterProvider) {
$uiRouterProvider.trace.enable(1);
@ -21,9 +20,12 @@ export default function AppConfig($uiRouterProvider) {
$stateRegistry.register({
name: 'scheduler',
url: '/account/:accountId/scheduler',
templateUrl: schedulerTmpl,
controller: 'SchedulerController',
controllerAs: 'schedulerCtrl'
component: 'scheduleComponent',
resolve: {
accountId: function($transition$) {
return $transition$.params().accountId;
}
}
});
$stateRegistry.register({

View File

@ -33,6 +33,8 @@ var ngMessages = require('angular-messages'),
ngUiNotification = require('angular-ui-notification'),
ngStrap = require('angular-strap');
var schedulerTmpl = require('./scheduler.html');
import { ScheduleController } from './schedule.controller';
import { ScheduleService } from './schedule.service';
@ -49,6 +51,13 @@ export default angular.module('accountant.scheduler', [
.factory('scheduleService', downgradeInjectable(ScheduleService))
.controller('SchedulerController', ScheduleController)
.component('scheduleComponent', {
bindings: {
accountId: '<'
},
templateUrl: schedulerTmpl,
controller: ScheduleController,
controllerAs: 'schedulerCtrl'
})
.name;

View File

@ -11,15 +11,17 @@ var scheduleFormTmpl = require('./schedule.form.tmpl.html'),
scheduleDeleteTmpl = require('./schedule.delete.tmpl.html');
export class ScheduleController{
accountId: number;
operations = [];
constructor(
private $stateParams,
private toastrService: ToastrService,
private scheduleService: ScheduleService,
private logger: Logger,
private $modal
) {
) {}
$onInit = function() {
// Load operations on controller initialization.
this.load();
}
@ -29,7 +31,7 @@ export class ScheduleController{
*/
add = function() {
var schedule = new Schedule();
schedule.account_id = this.$stateParams.accountId;
schedule.account_id = this.accountId;
return this.modify(schedule);
};
@ -38,9 +40,11 @@ export class ScheduleController{
* Load operations.
*/
load = function() {
return this.scheduleService.query(this.$stateParams.accountId)
return this.scheduleService.query(this.accountId)
.subscribe((schedules: Schedule[]) => {
this.operations = schedules;
}, (reason) => {
this.logger.log("Got error", reason);
}
);
};