OSDN Git Service

modified noteInfo api to returning user own notes
[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
56     if(note !== undefined) {
57         var baseNoteInfo = Restangular.all('/api/noteInfo/')
58         $scope.noteName = note
59
60         var params = {
61             note: note,
62             email: user.email
63         }
64
65         baseNoteInfo.post(params).then(function(commands) {
66             $scope.commands = commands 
67             commands.forEach(function(params) {
68                 var obj = {
69                     name: params.command,
70                     isCompleted: false,
71                 }
72                 $scope.commandDirectives.push(obj)
73             })
74         })
75
76         $scope.$on('requestParams', function(event, i) {
77             $scope.$broadcast('sendParams'+i, $scope.commands[i])
78         })
79     } else {
80         $scope.noteName = 'new note' 
81     }
82 });