Skip to content

Commit 868044c

Browse files
committed
Refactored services to become ES6 classes
1 parent cb772b5 commit 868044c

File tree

4 files changed

+92
-88
lines changed

4 files changed

+92
-88
lines changed

angular/index.services.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {APIService} from './services/API.service';
2+
import {DialogService} from './services/dialog.service';
3+
import {ToastService} from './services/toast.service';
4+
5+
angular.module('app.services')
6+
.factory('API', APIService)
7+
.factory('DialogService', DialogService)
8+
.factory('ToastService', ToastService)

angular/services/API.service.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
(function() {
2-
"use strict";
3-
4-
angular.module('app.services').factory('API', function(Restangular, ToastService, $localStorage) {
5-
1+
export class APIService {
2+
constructor(Restangular, ToastService, $localStorage) {
3+
'ngInject';
64
//content negotiation
75
var headers = {
86
'Content-Type': 'application/json',
@@ -26,6 +24,5 @@
2624
}
2725
});
2826
});
29-
});
30-
31-
})();
27+
}
28+
}

angular/services/dialog.service.js

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
1-
(function(){
2-
"use strict";
3-
4-
angular.module("app.services").factory('DialogService', function($mdDialog){
5-
6-
return {
7-
fromTemplate: function(template, options){
8-
if ( !template ){
9-
return false;
10-
}
11-
12-
if ( !options ){
13-
options = {};
14-
}
15-
16-
options.templateUrl = './views/dialogs/' + template + '/' + template + '.html'
17-
18-
return $mdDialog.show(options);
19-
},
20-
21-
hide: function(){
22-
return $mdDialog.hide();
23-
},
24-
25-
alert: function(title, content){
26-
$mdDialog.show(
27-
$mdDialog.alert()
28-
.title(title)
29-
.content(content)
30-
.ok('Ok')
31-
);
32-
},
33-
34-
confirm: function(title, content) {
35-
return $mdDialog.show(
36-
$mdDialog.confirm()
37-
.title(title)
38-
.content(content)
39-
.ok('Ok')
40-
.cancel('Cancel')
41-
);
42-
}
43-
};
44-
});
45-
})();
1+
export class DialogService {
2+
constructor($mdDialog) {
3+
'ngInject';
4+
5+
this.$mdDialog = $mdDialog
6+
}
7+
8+
fromTemplate(template, options) {
9+
if (!template) {
10+
return false;
11+
}
12+
13+
if (!options) {
14+
options = {};
15+
}
16+
17+
options.templateUrl = './views/dialogs/' + template + '/' + template + '.html'
18+
19+
return this.$mdDialog.show(options);
20+
}
21+
22+
hide() {
23+
return this.$mdDialog.hide();
24+
}
25+
26+
alert(title, content) {
27+
this.$mdDialog.show(
28+
this.$mdDialog.alert()
29+
.title(title)
30+
.content(content)
31+
.ok('Ok')
32+
);
33+
}
34+
35+
confirm(title, content) {
36+
return this.$mdDialog.show(
37+
this.$mdDialog.confirm()
38+
.title(title)
39+
.content(content)
40+
.ok('Ok')
41+
.cancel('Cancel')
42+
);
43+
}
44+
}

angular/services/toast.service.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
(function(){
2-
"use strict";
1+
export class ToastService {
2+
constructor($mdToast) {
3+
'ngInject';
34

4-
angular.module("app.services").factory('ToastService', function($mdToast){
5+
this.$mdToast = $mdToast;
56

6-
var delay = 6000,
7-
position = 'top right',
8-
action = 'OK';
7+
this.delay = 6000;
8+
this.position = 'top right';
9+
this.action = 'OK';
10+
}
911

10-
return {
11-
show: function(content){
12-
if (!content){
13-
return false;
14-
}
12+
show(content) {
13+
if (!content) {
14+
return false;
15+
}
1516

16-
return $mdToast.show(
17-
$mdToast.simple()
18-
.content(content)
19-
.position(position)
20-
.action(action)
21-
.hideDelay(delay)
22-
);
23-
},
24-
error: function(content){
25-
if (!content){
26-
return false;
27-
}
17+
return this.$mdToast.show(
18+
this.$mdToast.simple()
19+
.content(content)
20+
.position(this.position)
21+
.action(this.action)
22+
.hideDelay(this.delay)
23+
);
24+
}
2825

29-
return $mdToast.show(
30-
$mdToast.simple()
31-
.content(content)
32-
.position(position)
33-
.theme('warn')
34-
.action(action)
35-
.hideDelay(delay)
36-
);
37-
}
38-
};
39-
});
40-
})();
26+
error(content) {
27+
if (!content) {
28+
return false;
29+
}
30+
31+
return this.$mdToast.show(
32+
this.$mdToast.simple()
33+
.content(content)
34+
.position(this.position)
35+
.theme('warn')
36+
.action(this.action)
37+
.hideDelay(this.delay)
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)