Use component in scheduler route, inject accountId into.
This commit is contained in:
parent
3326dac51a
commit
c4c10f9ab7
@ -2,7 +2,6 @@
|
|||||||
import { Level } from '@nsalaun/ng-logger';
|
import { Level } from '@nsalaun/ng-logger';
|
||||||
|
|
||||||
var operationsTmpl = require('./operations/operations.html');
|
var operationsTmpl = require('./operations/operations.html');
|
||||||
var schedulerTmpl = require('./scheduler/scheduler.html');
|
|
||||||
|
|
||||||
export default function AppConfig($uiRouterProvider) {
|
export default function AppConfig($uiRouterProvider) {
|
||||||
$uiRouterProvider.trace.enable(1);
|
$uiRouterProvider.trace.enable(1);
|
||||||
@ -21,9 +20,12 @@ export default function AppConfig($uiRouterProvider) {
|
|||||||
$stateRegistry.register({
|
$stateRegistry.register({
|
||||||
name: 'scheduler',
|
name: 'scheduler',
|
||||||
url: '/account/:accountId/scheduler',
|
url: '/account/:accountId/scheduler',
|
||||||
templateUrl: schedulerTmpl,
|
component: 'scheduleComponent',
|
||||||
controller: 'SchedulerController',
|
resolve: {
|
||||||
controllerAs: 'schedulerCtrl'
|
accountId: function($transition$) {
|
||||||
|
return $transition$.params().accountId;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$stateRegistry.register({
|
$stateRegistry.register({
|
||||||
|
@ -33,6 +33,8 @@ var ngMessages = require('angular-messages'),
|
|||||||
ngUiNotification = require('angular-ui-notification'),
|
ngUiNotification = require('angular-ui-notification'),
|
||||||
ngStrap = require('angular-strap');
|
ngStrap = require('angular-strap');
|
||||||
|
|
||||||
|
var schedulerTmpl = require('./scheduler.html');
|
||||||
|
|
||||||
import { ScheduleController } from './schedule.controller';
|
import { ScheduleController } from './schedule.controller';
|
||||||
import { ScheduleService } from './schedule.service';
|
import { ScheduleService } from './schedule.service';
|
||||||
|
|
||||||
@ -49,6 +51,13 @@ export default angular.module('accountant.scheduler', [
|
|||||||
|
|
||||||
.factory('scheduleService', downgradeInjectable(ScheduleService))
|
.factory('scheduleService', downgradeInjectable(ScheduleService))
|
||||||
|
|
||||||
.controller('SchedulerController', ScheduleController)
|
.component('scheduleComponent', {
|
||||||
|
bindings: {
|
||||||
|
accountId: '<'
|
||||||
|
},
|
||||||
|
templateUrl: schedulerTmpl,
|
||||||
|
controller: ScheduleController,
|
||||||
|
controllerAs: 'schedulerCtrl'
|
||||||
|
})
|
||||||
|
|
||||||
.name;
|
.name;
|
||||||
|
@ -11,15 +11,17 @@ var scheduleFormTmpl = require('./schedule.form.tmpl.html'),
|
|||||||
scheduleDeleteTmpl = require('./schedule.delete.tmpl.html');
|
scheduleDeleteTmpl = require('./schedule.delete.tmpl.html');
|
||||||
|
|
||||||
export class ScheduleController{
|
export class ScheduleController{
|
||||||
|
accountId: number;
|
||||||
operations = [];
|
operations = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private $stateParams,
|
|
||||||
private toastrService: ToastrService,
|
private toastrService: ToastrService,
|
||||||
private scheduleService: ScheduleService,
|
private scheduleService: ScheduleService,
|
||||||
private logger: Logger,
|
private logger: Logger,
|
||||||
private $modal
|
private $modal
|
||||||
) {
|
) {}
|
||||||
|
|
||||||
|
$onInit = function() {
|
||||||
// Load operations on controller initialization.
|
// Load operations on controller initialization.
|
||||||
this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
@ -29,7 +31,7 @@ export class ScheduleController{
|
|||||||
*/
|
*/
|
||||||
add = function() {
|
add = function() {
|
||||||
var schedule = new Schedule();
|
var schedule = new Schedule();
|
||||||
schedule.account_id = this.$stateParams.accountId;
|
schedule.account_id = this.accountId;
|
||||||
|
|
||||||
return this.modify(schedule);
|
return this.modify(schedule);
|
||||||
};
|
};
|
||||||
@ -38,9 +40,11 @@ export class ScheduleController{
|
|||||||
* Load operations.
|
* Load operations.
|
||||||
*/
|
*/
|
||||||
load = function() {
|
load = function() {
|
||||||
return this.scheduleService.query(this.$stateParams.accountId)
|
return this.scheduleService.query(this.accountId)
|
||||||
.subscribe((schedules: Schedule[]) => {
|
.subscribe((schedules: Schedule[]) => {
|
||||||
this.operations = schedules;
|
this.operations = schedules;
|
||||||
|
}, (reason) => {
|
||||||
|
this.logger.log("Got error", reason);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user