OSDN Git Service

8ec0e17178ae80965d02bfa2995986e41dbac65a
[eos/zephyr.git] / client / app / components / board / board.controller.js
1 'use strict';
2
3 angular.module('zephyrApp')
4 .controller('BoardController', function ($scope, $modal, Restangular, $state, user) {
5
6     // Login check
7     if(user.getID() !== $state.params.userID) {
8         user.setID(null)
9         $state.go('login')
10     }
11
12
13     $scope.commandDirectives = []
14
15     // Add new my-command directive
16     $scope.openCommandModal = function() {
17         var modalInstance = $modal.open({
18             templateUrl: '/client/app/components/commandModal/commandModal.html',
19             controller: 'CommandModalController',
20             backdrop: true,
21             size: 'lg'
22         })
23         modalInstance.result.then(function(command) {
24             (function addCommandDirective() {
25                 var obj = {
26                     name: command,
27                     isCompleted: false
28                 }
29                 $scope.commandDirectives.push(obj)
30             })()
31         })
32     }
33
34     // Remove my-command directive
35     $scope.removeCommandDirective= function(index) {
36         $scope.commandDirectives.splice(index, 1)
37     }
38
39     // 
40     $scope.save = function() {
41         $modal.open({
42             templateUrl: '/client/app/components/saveFileModal/saveFileModal.html',
43             controller: 'SaveFileModalController',
44             backdrop: true,
45             scope: $scope
46         })
47     }
48     $scope.$on('updateParams', function(event, index, params) {
49         $scope.commandDirectives[index].params = params
50         $scope.commandDirectives[index].isCompleted = true
51     })
52
53     // restore executeion log
54     var note = $state.params.noteID
55     if(!note) {
56         $scope.noteName = note
57         var baseNoteInfo = Restangular.all('/api/noteInfo/'+note)
58         baseNoteInfo.getList().then(function(commands) {
59             $scope.commands = commands 
60             commands.forEach(function(params) {
61                 var obj = {
62                     name: params.command,
63                     isCompleted: false,
64                 }
65                 $scope.commandDirectives.push(obj)
66             })
67         })
68         $scope.$on('requestParams', function(event, i) {
69             $scope.$broadcast('sendParams'+i, $scope.commands[i])
70         })
71     } else {
72         $scope.noteName = 'new note' 
73     }
74 });