Skip to content

Commit 94ea918

Browse files
committed
Merge pull request #1 from aspnetboilerplate/abp-ng-module
Abp ng module merged
2 parents 34f7534 + f578dc0 commit 94ea918

File tree

10 files changed

+141
-71
lines changed

10 files changed

+141
-71
lines changed

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/Abp/Framework/scripts/abp.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
var abp = abp || {};
22
(function () {
33

4+
/* Application paths *****************************************/
5+
6+
//Current application root path (including virtual directory if exists).
7+
abp.appPath = abp.appPath || '/';
8+
9+
//Converts given path to absolute path using abp.appPath variable.
10+
abp.toAbsAppPath = function (path) {
11+
if (path.indexOf('/') == 0) {
12+
path = path.substring(1);
13+
}
14+
15+
return abp.appPath + path;
16+
};
17+
418
/* LOCALIZATON ***********************************************/
519
//Implements Localization API that simplifies usage of localization scripts generated by Abp.
620

721
abp.localization = abp.localization || {};
822

23+
abp.localization.defaultSourceName = undefined;
24+
925
abp.localization.localize = function (key, sourceName) {
26+
sourceName = sourceName || abp.localization.defaultSourceName;
27+
1028
var source = abp.localization.values[sourceName];
29+
1130
if (source == undefined) {
1231
abp.log.warn('Could not find localization source: ' + sourceName);
1332
return key;
@@ -248,5 +267,13 @@
248267

249268
return str;
250269
};
270+
271+
function endsWith(str, suffix) {
272+
if (suffix.length > str.length) {
273+
return false;
274+
}
275+
276+
return str.indexOf(suffix, str.length - suffix.length) !== -1;
277+
}
251278

252279
})();

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/Abp/Framework/scripts/libs/abp.spin.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@
5555
}
5656
}
5757

58-
if (options.promise) {
59-
options.promise.always(function () {
60-
abp.ui.clearBusy(elm);
61-
});
58+
if (options.promise) { //Supports Q and jQuery.Deferred
59+
if (options.promise.always) {
60+
options.promise.always(function () {
61+
abp.ui.clearBusy(elm);
62+
});
63+
} else if (options.promise.finally) {
64+
options.promise.finally(function () {
65+
abp.ui.clearBusy(elm);
66+
});
67+
}
6268
}
6369
};
6470

Original file line numberDiff line numberDiff line change
@@ -1,27 +1,76 @@
1-
var abp = abp || {};
2-
(function (angular) {
1+
(function (abp, angular) {
32

43
if (!angular) {
54
return;
65
}
76

8-
// 'abp' module ///////////////////////////////////////////////////////////
9-
107
var abpModule = angular.module('abp', []);
118

12-
abpModule.factory('services.tasksystem.task', ['$http', function ($http) {
13-
return new function() {
14-
this.getTasks = abp.services.tasksystem.task.getTasks;
15-
16-
//Working on this code!
17-
//this.getTasks = function(input) {
18-
// return $http({
19-
// url: '/api/services/tasksystem/task/GetTasks',
20-
// method: 'POST',
21-
// data: JSON.stringify(input)
22-
// });
23-
//};
24-
};
25-
}]);
26-
27-
})(angular || undefined);
9+
abpModule.config([
10+
'$httpProvider', function ($httpProvider) {
11+
$httpProvider.interceptors.push(function ($q) {
12+
13+
var defaultError = {
14+
message: 'Ajax request is not succeed!',
15+
details: 'Error detail is not sent by server.'
16+
};
17+
18+
return {
19+
20+
'request': function (config) {
21+
if (endsWith(config.url, '.cshtml')) {
22+
config.url = abp.appPath + 'AbpAppView/Load?viewUrl=' + config.url;
23+
}
24+
25+
return config;
26+
},
27+
28+
'response': function (response) {
29+
if (!response.config || !response.config.abp || !response.data) {
30+
return response;
31+
}
32+
33+
var originalData = response.data;
34+
var defer = $q.defer();
35+
36+
if (originalData.success === true) {
37+
response.data = originalData.result;
38+
defer.resolve(response);
39+
} else { //data.success === false
40+
if (originalData.error) {
41+
abp.message.error(originalData.error.message);
42+
} else {
43+
originalData.error = defaultError;
44+
}
45+
46+
abp.log.error(originalData.error.message + ' | ' + originalData.error.details);
47+
48+
response.data = originalData.error;
49+
defer.reject(response);
50+
51+
if (originalData.unAuthorizedRequest && !originalData.targetUrl) {
52+
location.reload();
53+
}
54+
}
55+
56+
if (originalData.targetUrl) {
57+
location.href = originalData.targetUrl;
58+
}
59+
60+
return defer.promise;
61+
}
62+
63+
};
64+
});
65+
}
66+
]);
67+
68+
function endsWith(str, suffix) {
69+
if (suffix.length > str.length) {
70+
return false;
71+
}
72+
73+
return str.indexOf(suffix, str.length - suffix.length) !== -1;
74+
}
75+
76+
})((abp || (abp = {})), (angular || undefined));

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/App/Main/app.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
(function () {
22
'use strict';
33

4-
var getViewUrl = function (path) {
5-
return '/AbpAppView/Load?viewUrl=/App/Main/views/' + path + '.cshtml';
6-
};
7-
84
var app = angular.module('app', [
95
'ngAnimate',
106
'ngRoute',
@@ -21,16 +17,16 @@
2117
function getRoutes() {
2218
return [
2319
{
24-
url: '/', //default: /task/new
20+
url: '/', //default: /task/list
2521
config: {
26-
templateUrl: getViewUrl('task/list'),
22+
templateUrl: '/App/Main/views/task/list.cshtml',
2723
menuItem: 'TaskList'
2824
}
2925
},
3026
{
3127
url: '/task/new',
3228
config: {
33-
templateUrl: getViewUrl('task/new'),
29+
templateUrl: '/App/Main/views/task/new.cshtml',
3430
menuItem: 'NewTask'
3531
}
3632
}
@@ -44,7 +40,7 @@
4440
$routeProvider.when(r.url, r.config);
4541
});
4642

47-
$routeProvider.otherwise({ redirectTo: '/' });
43+
$routeProvider.otherwise({ redirectTo: abp.appPath });
4844
}
4945

5046
app.run(['$rootScope', '$location', '$routeParams', '$route', function ($rootScope, $location, $routeParams, $route) {

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/App/Main/views/task/list.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var controllerId = 'sts.controllers.views.task.list';
33
var app = angular.module('app');
44

5-
app.controller(controllerId, ['$scope', 'services.tasksystem.task', function ($scope, taskService) {
5+
app.controller(controllerId, ['$scope', 'abp.services.tasksystem.task', function ($scope, taskService) {
66
var vm = this;
77

88
vm.tasks = [];
@@ -18,10 +18,8 @@
1818
vm.refreshTasks = function () {
1919
taskService.getTasks({
2020
state: $scope.selectedTaskState > 0 ? $scope.selectedTaskState : null
21-
}).done(function (data) {
22-
$scope.$apply(function() {
23-
vm.tasks = data.tasks;
24-
});
21+
}).success(function (data) {
22+
vm.tasks = data.tasks;
2523
});
2624
};
2725

@@ -33,22 +31,17 @@
3331
newState = 1;
3432
}
3533

36-
abp.services.tasksystem.task.updateTask({
34+
taskService.updateTask({
3735
taskId: task.id,
3836
state: newState
39-
}).done(function () {
40-
$scope.$apply(function () {
41-
task.state = newState;
42-
});
43-
37+
}).success(function () {
38+
task.state = newState;
4439
abp.notify.info(vm.localize('TaskUpdatedMessage'));
4540
});
4641
};
4742

4843
vm.getTaskCountText = function () {
4944
return abp.utils.formatString(vm.localize('Xtasks'), vm.tasks.length);
5045
};
51-
52-
vm.refreshTasks();
5346
}]);
5447
})();

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/App/Main/views/task/new.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div ng-controller="sts.controllers.views.task.new as vm">
2-
<form role="form" name="newTaskForm" novalidate>
2+
<form id="NewTaskForm" role="form" name="newTaskForm" novalidate>
33
<div class="form-group">
44
<label for="TaskDescription">@L("TaskDescription")</label>
55
<textarea id="TaskDescription" ng-model="vm.task.description" class="form-control" rows="3" placeholder="@L("EnterDescriptionHere")" required></textarea>
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
(function () {
1+
(function() {
22
var controllerId = 'sts.controllers.views.task.new';
33
var app = angular.module('app');
4-
app.controller(controllerId, ['$scope', '$location', function ($scope, $location) {
5-
var vm = this;
4+
app.controller(controllerId, [
5+
'$scope', '$location', 'abp.services.tasksystem.task', 'abp.services.tasksystem.person',
6+
function($scope, $location, taskService, personService) {
7+
var vm = this;
68

7-
vm.task = {
8-
description: '',
9-
assignedPersonId: null
10-
};
9+
vm.task = {
10+
description: '',
11+
assignedPersonId: null
12+
};
1113

12-
var localize = abp.localization.getSource('SimpleTaskSystem');
14+
var localize = abp.localization.getSource('SimpleTaskSystem');
1315

14-
vm.people = []; //TODO: Move Person combo to a directive
16+
vm.people = []; //TODO: Move Person combo to a directive?
1517

16-
abp.services.tasksystem.person.getAllPeople({}).done(function (data) {
17-
$scope.$apply(function () {
18+
personService.getAllPeople().success(function(data) {
1819
vm.people = data.people;
1920
});
20-
});
2121

22-
vm.saveTask = function () {
23-
abp.ui.setBusy($('#NewTaskForm'), {
24-
promise: abp.services.tasksystem.task.createTask(vm.task)
25-
.done(function () {
26-
abp.notify.info(abp.utils.formatString(localize("TaskCreatedMessage"), vm.task.description));
27-
$scope.$apply(function () {
22+
vm.saveTask = function() {
23+
abp.ui.setBusy(null, {
24+
promise: taskService.createTask(vm.task)
25+
.success(function() {
26+
abp.notify.info(abp.utils.formatString(localize("TaskCreatedMessage"), vm.task.description));
2827
$location.path('/'); //TODO: Look for a better way!
29-
});
30-
})
31-
});
32-
};
28+
})
29+
});
30+
};
3331

34-
}]);
32+
}
33+
]);
3534
})();

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/Views/Home/Index.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<script src="~/Scripts/angular-ui/ui-utils.min.js"></script>
1717

1818
<script src="~/Abp/Framework/scripts/libs/angular/abp.ng.js"></script>
19+
<script src="~/api/AbpServiceProxies/GetAll?type=angular"></script>
1920

2021
<script src="~/App/Main/app.js"></script>
2122

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.WebApi/SimpleTaskSystem.WebApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</Reference>
4545
<Reference Include="Abp.Web.Api, Version=0.2.2.1, Culture=neutral, processorArchitecture=MSIL">
4646
<SpecificVersion>False</SpecificVersion>
47-
<HintPath>..\packages\Abp.Web.Api.0.2.2.1\lib\net451\Abp.Web.Api.dll</HintPath>
47+
<HintPath>..\..\..\aspnetboilerplate\src\Abp\Framework\Abp.Web.Api\bin\Release\Abp.Web.Api.dll</HintPath>
4848
</Reference>
4949
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
5050
<SpecificVersion>False</SpecificVersion>

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.WebApi/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<package id="Abp" version="0.2.2.1" targetFramework="net451" />
44
<package id="Abp.Application" version="0.2.2.1" targetFramework="net451" />
55
<package id="Abp.Web" version="0.2.2.1" targetFramework="net451" />
6-
<package id="Abp.Web.Api" version="0.2.2.1" targetFramework="net451" />
76
<package id="Castle.Core" version="3.3.0" targetFramework="net451" />
87
<package id="Castle.Core-log4net" version="3.3.0" targetFramework="net451" />
98
<package id="Castle.LoggingFacility" version="3.3.0" targetFramework="net451" />

0 commit comments

Comments
 (0)