Преглед изворни кода

add/edit controller

tags/v0.1.0
Robin Thoni пре 8 година
родитељ
комит
4526f5e057

+ 39
- 9
app/app.js Прегледај датотеку

@@ -22,8 +22,12 @@ angular.module('app', [
22 22
             //         'default': '700'
23 23
             //     });
24 24
 
25
+            // $mdThemingProvider.theme('default')
26
+            //     .primaryPalette('blue')
27
+            //     .accentPalette('pink');
28
+
25 29
             $mdIconProvider
26
-                .icon('md-toggle-arrow', 'img/arrow.svg') ;
30
+                .icon('md-toggle-arrow', 'img/arrow.svg');
27 31
 
28 32
             ssSideNavSectionsProvider.initWithTheme($mdThemingProvider);
29 33
             ssSideNavSectionsProvider.initWithSections([{
@@ -70,12 +74,16 @@ angular.module('app', [
70 74
                 name: 'PkGuid',
71 75
                 type: 'heading',
72 76
                 children: [{
73
-                    name: 'PkGuid 1',
77
+                    name: 'PkGuids',
74 78
                     type: 'toggle',
75 79
                     pages: [{
76 80
                         id: 'toogle_2_link_1',
77
-                        name: 'PkGuid 1 1',
81
+                        name: 'All',
78 82
                         state: 'pkguid'
83
+                    },{
84
+                        id: 'toogle_2_link_1',
85
+                        name: 'New',
86
+                        state: 'pkguid_add'
79 87
                     }]
80 88
                 }]
81 89
             }]);
@@ -99,7 +107,7 @@ angular.module('app', [
99 107
             });
100 108
 
101 109
             $stateProvider.state('pkguid', {
102
-                url:'/pkguid',
110
+                url:'/pkguids',
103 111
                 parent: 'root',
104 112
                 title: "PkGuid",
105 113
                 reloadOnSearch: false,
@@ -107,6 +115,27 @@ angular.module('app', [
107 115
                 controller:'PkGuidController'
108 116
             });
109 117
 
118
+            $stateProvider.state('pkguid_add', {
119
+                url:'/pkguids/add',
120
+                parent: 'root',
121
+                title: "New PkGuid",
122
+                reloadOnSearch: false,
123
+                templateUrl:'views/pkguidedit.html',
124
+                controller:'PkGuidEditController'
125
+            });
126
+
127
+            $stateProvider.state('pkguid_edit', {
128
+                url:'/pkguids/edit/:id',
129
+                parent: 'root',
130
+                title: "Edit PkGuid",
131
+                reloadOnSearch: false,
132
+                templateUrl:'views/pkguidedit.html',
133
+                controller:'PkGuidEditController',
134
+                params: {
135
+                    pkguid: null
136
+                }
137
+            });
138
+
110 139
             $urlRouterProvider.otherwise('/');
111 140
     }])
112 141
     .directive('dateNow', ['$filter', function($filter) {
@@ -116,9 +145,10 @@ angular.module('app', [
116 145
             }
117 146
         };
118 147
     }])
119
-    .run(['$rootScope', '$state',
120
-        function ($rootScope, $state) {
121
-            $rootScope.$on('$stateChangeSuccess', function (event, current, previous) {
122
-                $rootScope.title = current.title + " - App";
123
-            });
148
+    .run(['$rootScope', '$transitions', function ($rootScope, $transitions) {
149
+        $transitions.onSuccess({}, function($transitions)
150
+        {
151
+            var toState = $transitions.$to();
152
+            $rootScope.title = toState.title + " - App";
153
+        });
124 154
     }]);

+ 6
- 21
app/controllers/pkguid.controller.js Прегледај датотеку

@@ -1,6 +1,6 @@
1 1
 angular.module('app')
2
-    .controller('PkGuidController', ['$scope', '$state', '$mdDialog', 'pkGuidBusiness',
3
-        function($scope, $state, $mdDialog, pkGuidBusiness) {
2
+    .controller('PkGuidController', ['$scope', 'pkGuidBusiness', 'AppUtilsBusiness',
3
+        function($scope, pkGuidBusiness, AppUtilsBusiness) {
4 4
 
5 5
             $scope.selected = [];
6 6
 
@@ -11,36 +11,21 @@ angular.module('app')
11 11
             };
12 12
 
13 13
             $scope.pkGuids = null;
14
-            $scope.pkGuidsError = null;
14
+            $scope.error = null;
15 15
 
16 16
             $scope.getPkGuids = function()
17 17
             {
18
-                $scope.pkGuidsError = null;
19
-                var orderBy = $scope.query.order;
20
-                if (orderBy[0] == '-') {
21
-                    orderBy = orderBy.substr(1) + ":DESC";
22
-                }
23
-                else {
24
-                    orderBy = orderBy + ":ASC";
25
-                }
18
+                $scope.error = null;
19
+                var orderBy = AppUtilsBusiness.convertOrderBy($scope.query.order);
26 20
                 $scope.promise = pkGuidBusiness.getMultiple(orderBy, $scope.query.page - 1, $scope.query.limit).then(function(data)
27 21
                 {
28 22
                     $scope.pkGuids = data;
29
-                    $scope.pkGuidsError = null;
30 23
                 }, function(error)
31 24
                 {
32 25
                     $scope.pkGuids = null;
33
-                    $scope.pkGuidsError = error;
26
+                    $scope.error = error;
34 27
                 });
35 28
             };
36 29
 
37 30
             $scope.getPkGuids();
38
-
39
-            // pkGuidBusiness.getSingleById('42').then(function(data)
40
-            // {
41
-            //     console.log(data);
42
-            // }, function(error)
43
-            // {
44
-            //     console.error(error);
45
-            // });
46 31
     }]);

+ 62
- 0
app/controllers/pkguidedit.controller.js Прегледај датотеку

@@ -0,0 +1,62 @@
1
+angular.module('app')
2
+    .controller('PkGuidEditController', ['$scope', '$state', '$mdDialog', 'pkGuidBusiness',
3
+        function ($scope, $state, $mdDialog, pkGuidBusiness) {
4
+
5
+            $scope.pkguid = null;
6
+            $scope.defaultPkguid = {
7
+                id: null,
8
+                someText: "Test.",
9
+                someInt: 42
10
+            };
11
+
12
+            $scope.running = false;
13
+
14
+            $scope.error = null;
15
+
16
+            if ($state.params != null) {
17
+                if ($state.params.pkguid != null) {
18
+                    $scope.pkguid = $state.params.pkguid;
19
+                }
20
+                else if ($state.params.id != null) {
21
+                    $scope.running = true;
22
+                    pkGuidBusiness.getSingleById($state.params.id).then(function(data)
23
+                    {
24
+                        $scope.running = false;
25
+                        $scope.pkguid = data;
26
+                    }, function (error) {
27
+                        $scope.running = false;
28
+                        $scope.error = error;
29
+                    });
30
+                }
31
+                else {
32
+                    $scope.pkguid = angular.copy($scope.defaultPkguid);
33
+                }
34
+            }
35
+            else {
36
+                $scope.pkguid = angular.copy($scope.defaultPkguid);
37
+            }
38
+
39
+            $scope.submit = function () {
40
+                $scope.error = null;
41
+                $scope.running = true;
42
+                if ($scope.pkguid.id == null) {
43
+                    pkGuidBusiness.addDbo($scope.pkguid).then(function (data) {
44
+                        $scope.running = false;
45
+                        $state.go('pkguid_edit', {pkguid: data, id: data.id});
46
+                    }, function (error) {
47
+                        $scope.running = false;
48
+                        $scope.error = error;
49
+                    });
50
+                }
51
+                else {
52
+                    pkGuidBusiness.editSingleByIdDbo($scope.pkguid.id, $scope.pkguid).then(function (data) {
53
+                        $scope.running = false;
54
+                        $scope.pkguid = data;
55
+                    }, function (error) {
56
+                        $scope.running = false;
57
+                        $scope.error = error;
58
+                    });
59
+                }
60
+            };
61
+
62
+        }]);

BIN
app/fonts/MaterialIcons-Regular.eot Прегледај датотеку


BIN
app/fonts/MaterialIcons-Regular.ttf Прегледај датотеку


BIN
app/fonts/MaterialIcons-Regular.woff Прегледај датотеку


BIN
app/fonts/MaterialIcons-Regular.woff2 Прегледај датотеку


+ 0
- 4
app/img/menu.svg Прегледај датотеку

@@ -1,4 +0,0 @@
1
-<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18">
2
-    <path d="M0 0h18v18h-18z" fill="none"/>
3
-    <path d="M2 13.5h14v-1.5h-14v1.5zm0-4h14v-1.5h-14v1.5zm0-5.5v1.5h14v-1.5h-14z"/>
4
-</svg>

+ 2
- 0
app/index.html Прегледај датотеку

@@ -52,11 +52,13 @@
52 52
     <script src="controllers/toolbar.controller.js"></script>
53 53
     <script src="controllers/home.controller.js"></script>
54 54
     <script src="controllers/pkguid.controller.js"></script>
55
+    <script src="controllers/pkguidedit.controller.js"></script>
55 56
 
56 57
     <!-- Modal Controller -->
57 58
 
58 59
     <!-- SDK -->
59 60
     <script src="../sdk/sdk.js"></script>
61
+    <script src="../sdk/Business/apputils.business.js"></script>
60 62
     <script src="../sdk/DataAccess/pkguid.dataaccess.js"></script>
61 63
     <script src="../sdk/Business/pkguid.business.js"></script>
62 64
 

+ 44
- 0
app/less/app.less Прегледај датотеку

@@ -64,6 +64,50 @@ md-sidenav {
64 64
   height: 100%;
65 65
 }
66 66
 
67
+md-toolbar.md-table-toolbar.alternate .md-toolbar-tools {
68
+  color: #1e88e5;
69
+  font-size: 16px;
70
+  background-color: #e3f2fd;
71
+}
72
+
67 73
 /**
68 74
 ========================================================
69 75
 **/
76
+
77
+
78
+@font-face {
79
+  font-family: 'Material Icons';
80
+  font-style: normal;
81
+  font-weight: 400;
82
+  src: url(../fonts/MaterialIcons-Regular.eot); /* For IE6-8 */
83
+  src: local('Material Icons'),
84
+  local('MaterialIcons-Regular'),
85
+  url(../fonts/MaterialIcons-Regular.woff2) format('woff2'),
86
+  url(../fonts/MaterialIcons-Regular.woff) format('woff'),
87
+  url(../fonts/MaterialIcons-Regular.ttf) format('truetype');
88
+}
89
+
90
+.material-icons {
91
+  font-family: 'Material Icons';
92
+  font-weight: normal;
93
+  font-style: normal;
94
+  font-size: 24px;  /* Preferred icon size */
95
+  display: inline-block;
96
+  line-height: 1;
97
+  text-transform: none;
98
+  letter-spacing: normal;
99
+  word-wrap: normal;
100
+  white-space: nowrap;
101
+  direction: ltr;
102
+
103
+  /* Support for all WebKit browsers. */
104
+  -webkit-font-smoothing: antialiased;
105
+  /* Support for Safari and Chrome. */
106
+  text-rendering: optimizeLegibility;
107
+
108
+  /* Support for Firefox. */
109
+  -moz-osx-font-smoothing: grayscale;
110
+
111
+  /* Support for IE. */
112
+  font-feature-settings: 'liga';
113
+}

+ 36
- 7
app/views/pkguid.html Прегледај датотеку

@@ -1,18 +1,32 @@
1 1
 <div layout="column" layout-fill layout-align="top">
2 2
 
3 3
     <div flex>
4
-        <md-toolbar class="md-table-toolbar md-default">
4
+        <md-toolbar class="md-table-toolbar md-default" ng-show="selected.length == 0">
5 5
             <div class="md-toolbar-tools">
6 6
                 <span>PkGuids</span>
7
+                <span flex></span>
8
+                <a ui-sref="pkguid_add">
9
+                    <md-button class="md-icon-button" ng-click="">
10
+                        <md-icon class="material-icons">add</md-icon>
11
+                    </md-button>
12
+                </a>
13
+                <md-button class="md-icon-button" ng-click="getPkGuids()">
14
+                    <md-icon class="material-icons">refresh</md-icon>
15
+                </md-button>
16
+            </div>
17
+        </md-toolbar>
18
+        <md-toolbar class="md-table-toolbar alternate" ng-show="selected.length > 0">
19
+            <div class="md-toolbar-tools">
20
+                <span>{{selected.length}} {{selected.length > 1 ? 'PkGuids' : 'PkGuid'}} selected</span>
21
+                <span flex></span>
22
+                <md-button class="md-icon-button">
23
+                    <md-icon class="material-icons">delete</md-icon>
24
+                </md-button>
7 25
             </div>
8 26
         </md-toolbar>
9 27
     </div>
10 28
 
11 29
     <div flex>
12
-        <div class="isa_error" ng-show="pkGuidsError != null">
13
-            <i class="fa fa-times-circle"></i>
14
-            {{ pkGuidsError.data.message }}
15
-        </div>
16 30
         <md-table-container>
17 31
             <table md-table md-row-select multiple ng-model="selected" md-progress="promise">
18 32
                 <thead md-head md-order="query.order" md-on-reorder="getPkGuids">
@@ -21,14 +35,24 @@
21 35
                     <th md-column md-order-by="someText"><span>Some Text</span></th>
22 36
                     <th md-column md-order-by="someInt" md-numeric>Some Int</th>
23 37
                     <th md-column md-order-by="createdAt">Created At</th>
38
+                    <th md-column md-order-by="updatedAt">Updated At</th>
24 39
                 </tr>
25 40
                 </thead>
26 41
                 <tbody md-body>
27
-                <tr md-row md-select="item" md-select-id="id" md-auto-select ng-repeat="item in pkGuids.data">
42
+                <tr md-row md-select="item" md-select-id="id" ng-repeat="item in pkGuids.data">
28 43
                     <td md-cell>{{item.id}}</td>
29 44
                     <td md-cell>{{item.someText}}</td>
30 45
                     <td md-cell>{{item.someInt}}</td>
31
-                    <td md-cell>{{item.createdAt}}</td>
46
+                    <td md-cell>{{item.createdAt | date : 'medium'}}</td>
47
+                    <td md-cell>
48
+                        {{item.updatedAt == null ? 'Never' : item.updatedAt | date : 'medium'}}
49
+                        <span flex></span>
50
+                        <a ui-sref="pkguid_edit({id: item.id, pkguid: item})">
51
+                            <md-button class="md-icon-button">
52
+                                <md-icon class="material-icons">mode_edit</md-icon>
53
+                            </md-button>
54
+                        </a>
55
+                    </td>
32 56
                 </tr>
33 57
                 </tbody>
34 58
             </table>
@@ -36,4 +60,9 @@
36 60
     </div>
37 61
 
38 62
     <md-table-pagination class="col-xs-11" md-limit="query.limit" md-limit-options="[1, 5, 10, 15]" md-page="query.page" md-total="{{pkGuids.count}}" md-on-paginate="getPkGuids" md-page-select></md-table-pagination>
63
+
64
+    <div class="isa_error" ng-show="error != null">
65
+        <i class="fa fa-times-circle"></i>
66
+        {{ error.data.message }}
67
+    </div>
39 68
 </div>

+ 27
- 0
app/views/pkguidedit.html Прегледај датотеку

@@ -0,0 +1,27 @@
1
+<div layout="column" ng-cloak class="md-inline-form">
2
+    <md-content layout-padding>
3
+        <form name="editForm">
4
+            <div layout-gt-sm="row">
5
+                <md-input-container class="md-block" flex-gt-sm>
6
+                    <label>SomeText</label>
7
+                    <input required ng-model="pkguid.someText">
8
+                </md-input-container>
9
+
10
+                <md-input-container class="md-block" flex-gt-sm>
11
+                    <label>Some Int</label>
12
+                    <input required type="number" ng-model="pkguid.someInt">
13
+                </md-input-container>
14
+            </div>
15
+            <div flex>
16
+                <md-progress-linear ng-disabled="!running" md-mode="indeterminate"></md-progress-linear>
17
+            </div>
18
+            <div>
19
+                <md-button type="submit" ng-click="!editForm.$invalid && submit()">Submit</md-button>
20
+            </div>
21
+            <div class="isa_error" ng-show="error != null">
22
+                <i class="fa fa-times-circle"></i>
23
+                {{ error.data.message }}
24
+            </div>
25
+        </form>
26
+    </md-content>
27
+</div>

+ 1
- 1
app/views/toolbar.html Прегледај датотеку

@@ -1,7 +1,7 @@
1 1
 <md-toolbar layout="row" ng-controller="ToolBarController">
2 2
     <div class="md-toolbar-tools">
3 3
         <md-button class="md-icon-button" aria-label="Toolbar" ng-click="toggleSideBar()" hide-gt-md>
4
-            <md-icon md-svg-icon="img/menu.svg"></md-icon>
4
+            <md-icon class="material-icons">menu</md-icon>
5 5
         </md-button>
6 6
         <h2>Toolbar</h2>
7 7
         <span flex></span>

+ 2
- 1
bower.json Прегледај датотеку

@@ -15,6 +15,7 @@
15 15
     "angular-material": "1.1.x",
16 16
     "angular-material-data-table": "^0.10.9",
17 17
     "components-font-awesome": "^4.7.0",
18
-    "angular-material-sidenav": "^0.0.14"
18
+    "angular-material-sidenav": "^0.0.14",
19
+    "material-design-icons": "^3.0.1"
19 20
   }
20 21
 }

+ 26
- 0
sdk/Business/apputils.business.js Прегледај датотеку

@@ -0,0 +1,26 @@
1
+/**
2
+ * Created by robin on 12/15/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+
8
+    angular.module('appSdk')
9
+        .factory('AppUtilsBusiness', [function () {
10
+
11
+            var AppUtilsBusiness = {};
12
+
13
+            AppUtilsBusiness.convertOrderBy = function(orderBy)
14
+            {
15
+                if (orderBy[0] == '-') {
16
+                    orderBy = orderBy.substr(1) + ":DESC";
17
+                }
18
+                else {
19
+                    orderBy = orderBy + ":ASC";
20
+                }
21
+                return orderBy;
22
+            };
23
+
24
+            return AppUtilsBusiness;
25
+        }]);
26
+})();

Loading…
Откажи
Сачувај