Skip to content

Commit c362bdf

Browse files
committed
Working on dynamic angular javascript proxy
1 parent 67b0133 commit c362bdf

File tree

8 files changed

+50
-62
lines changed

8 files changed

+50
-62
lines changed

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

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/Abp/Framework/scripts/libs/angular/abp.ng.js

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,31 @@
2121
return response;
2222
}
2323

24+
var originalData = response.data;
2425
var defer = $q.defer();
2526

26-
if (response.data.success === true) {
27-
response.data = response.data.result;
27+
if (originalData.success === true) {
28+
response.data = originalData.result;
2829
defer.resolve(response);
2930
} else { //data.success === false
30-
if (response.data.error) {
31-
abp.message.error(response.data.error.message);
31+
if (originalData.error) {
32+
abp.message.error(originalData.error.message);
3233
} else {
33-
response.data.error = defaultError;
34+
originalData.error = defaultError;
3435
}
3536

36-
abp.log.error(response.data.error.message + ' | ' + response.data.error.details);
37+
abp.log.error(originalData.error.message + ' | ' + originalData.error.details);
3738

38-
response.data = response.data.error;
39+
response.data = originalData.error;
3940
defer.reject(response);
4041

41-
if (response.data.unAuthorizedRequest && !response.data.targetUrl) {
42+
if (originalData.unAuthorizedRequest && !originalData.targetUrl) {
4243
location.reload();
4344
}
4445
}
4546

46-
if (response.data.targetUrl) {
47-
location.href = data.targetUrl;
47+
if (originalData.targetUrl) {
48+
location.href = originalData.targetUrl;
4849
}
4950

5051
return defer.promise;
@@ -54,19 +55,4 @@
5455
}
5556
]);
5657

57-
abpModule.factory('services.tasksystem.task', [
58-
'$http', function ($http) {
59-
return new function () {
60-
this.getTasks = function (input) {
61-
return $http({
62-
url: '/api/services/tasksystem/task/GetTasks',
63-
method: 'POST',
64-
data: JSON.stringify(input),
65-
abp: true
66-
});
67-
};
68-
};
69-
}
70-
]);
71-
7258
})((abp || (abp = {})), (angular || undefined));

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

Lines changed: 4 additions & 7 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 = [];
@@ -31,14 +31,11 @@
3131
newState = 1;
3232
}
3333

34-
abp.services.tasksystem.task.updateTask({
34+
taskService.updateTask({
3535
taskId: task.id,
3636
state: newState
37-
}).done(function () {
38-
$scope.$apply(function () {
39-
task.state = newState;
40-
});
41-
37+
}).success(function () {
38+
task.state = newState;
4239
abp.notify.info(vm.localize('TaskUpdatedMessage'));
4340
});
4441
};

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)