Skip to content

Commit d91ebbc

Browse files
authored
Merge pull request #3 from liuliquan/dev
tags sync
2 parents 0c35976 + 3ebc4f9 commit d91ebbc

File tree

8 files changed

+489
-16
lines changed

8 files changed

+489
-16
lines changed

src/app/app.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,20 @@ angular.module('supportAdminApp', [
9999
url: '/tags',
100100
templateUrl: 'app/tags/tags.html',
101101
data: { pageTitle: 'Tags' },
102-
controller: function ($scope, $state) {
102+
controller: function ($scope, $state, TagService) {
103103
$scope.$state = $state;
104104
$scope.tagDomains = [{
105105
value: 'skills',
106106
name: 'Skills'
107107
}, {
108108
value: 'events',
109109
name: 'Events'
110+
}, {
111+
value: 'technology',
112+
name: 'Technology'
113+
}, {
114+
value: 'platform',
115+
name: 'Platform'
110116
}];
111117

112118
$scope.tagCategories = [{
@@ -128,6 +134,21 @@ angular.module('supportAdminApp', [
128134
value: 'pending',
129135
name: 'Pending'
130136
}];
137+
138+
TagService.getTechnologyStatuses().then(function(techStatuses) {
139+
_.forEach(techStatuses, function(status) {
140+
status.value = _.lowerCase(status.description);
141+
status.name = status.description;
142+
});
143+
$scope.techStatuses = techStatuses;
144+
});
145+
$scope.getTagStatuses = function(domainType) {
146+
if (domainType === 'technology') {
147+
return $scope.techStatuses;
148+
} else {
149+
return $scope.tagStatuses;
150+
}
151+
}
131152
}
132153
})
133154
.state('index.tags.list', {

src/app/tags/tags.edit.controller.js

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ module.controller('EditTagCtrl', ['$rootScope','$scope', 'TagService', '$state',
1414
$scope.loading = false;
1515
$timeout(function(){
1616
$scope.editTag = data;
17+
$scope.editTag.previousDomain = data.domain;
1718
$scope.editForm.synonyms = Array.isArray($scope.editTag.synonyms)? $scope.editTag.synonyms.join(','):'';
1819
angular.forEach($scope.tagCategories, function(c){
20+
$scope.editTag.categories = $scope.editTag.categories || [];
1921
if($scope.editTag.categories.indexOf(c.value) !== -1 ){
2022
$scope.editCategories.options.push(c);
2123
}
@@ -43,7 +45,7 @@ module.controller('EditTagCtrl', ['$rootScope','$scope', 'TagService', '$state',
4345
angular.forEach($scope.editCategories.options, function(c){
4446
$scope.editTag.categories.push(c.value);
4547
});
46-
$tagService.updateTag($scope.editTag).then(function(){
48+
$tagService.updateTagSync($scope.editTag).then(function(){
4749
$state.go('index.tags.list');
4850
},
4951
function(error) {

src/app/tags/tags.edit.html

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ <h2><strong>Details</strong></h2>
3939
<div class="row">
4040
<div class="form-group col-md-2" ng-class="{'has-error': editForm.selectedTagStatus.$touched && editForm.selectedTagStatus.$invalid}">
4141
<label for="tag-status">Status</label>
42-
<select id="tag-status" class="form-control m-b" ng-options="tagStatus.value as tagStatus.name for tagStatus in tagStatuses" ng-model="editTag.status" name="selectedTagStatus">
42+
<select id="tag-status" class="form-control m-b" ng-options="tagStatus.value as tagStatus.name for tagStatus in getTagStatuses(editTag.domain)" ng-model="editTag.status" name="selectedTagStatus" required>
4343
</select>
4444
<div class="help-block" ng-messages="editForm.selectedTagStatus.$error" ng-show="editForm.selectedTagStatus.$touched">
4545
<div ng-messages-include="errorMessages.html"></div>

src/app/tags/tags.list.controller.js

100644100755
Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
var module = angular.module('supportAdminApp');
44

5-
module.controller('TagListCtrl', ['$scope', '$rootScope', '$timeout', '$state', '$uibModal',
5+
module.controller('TagListCtrl', ['$scope', '$rootScope', '$timeout', '$interval', '$state', '$uibModal',
66
'AuthService', 'TagService',
7-
function ($scope, $rootScope, $timeout, $state, $modal, $authService, $tagService) {
7+
function ($scope, $rootScope, $timeout, $interval, $state, $modal, $authService, $tagService) {
88
/**
99
* Check if user is logged in
1010
*/
@@ -46,6 +46,9 @@ module.controller('TagListCtrl', ['$scope', '$rootScope', '$timeout', '$state',
4646
$scope.isLoading = false;
4747
// find tags by name
4848
$scope.findTag = function () {
49+
if ($scope.isSyncing) {
50+
return;
51+
}
4952
$scope.isLoading = true;
5053
$tagService.findTags($scope.tagName).then(
5154
function (tags) {
@@ -68,11 +71,11 @@ module.controller('TagListCtrl', ['$scope', '$rootScope', '$timeout', '$state',
6871
$state.go("index.tags.edit", {tagId: id});
6972
};
7073
//delete tag by id
71-
$scope.deleteTag = function (id) {
74+
$scope.deleteTag = function (tag) {
7275
if (!confirm('Are you sure want to delete this tag?')) {
7376
return;
7477
}
75-
$tagService.deleteTag(id).then(
78+
$tagService.deleteTagSync(tag).then(
7679
function () {
7780
$scope.findTag();
7881
},
@@ -83,6 +86,38 @@ module.controller('TagListCtrl', ['$scope', '$rootScope', '$timeout', '$state',
8386
});
8487
});
8588
};
86-
$scope.findTag();
89+
90+
var SYNC_INTERVAL = 2 * 60 * 1000;
91+
$scope.isSyncing = false;
92+
$scope.syncTags = function () {
93+
if ($scope.isSyncing) {
94+
return;
95+
}
96+
$scope.isLoading = true;
97+
$scope.isSyncing = true;
98+
$tagService.syncTags($scope).then(
99+
function (tags) {
100+
$scope.isSyncing = false;
101+
if (!$scope.tagName) {
102+
$scope.tags = tags;
103+
$timeout(function () {
104+
$scope.isLoading = false;
105+
$('.footable').trigger('footable_redraw');
106+
}, 300);
107+
} else {
108+
$scope.findTag();
109+
}
110+
},
111+
function (error) {
112+
$scope.isLoading = false;
113+
$scope.isSyncing = false;
114+
$scope.$broadcast('alert.AlertIssued', {
115+
type: 'danger',
116+
message: error.error
117+
});
118+
});
119+
};
120+
$scope.syncTags();
121+
$interval($scope.syncTags, SYNC_INTERVAL);
87122
}
88123
]);

src/app/tags/tags.list.html

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<td>
7979
<div class="row">
8080
<div class="col-md-3">
81-
<a href="javascript:;" data-ng-click='deleteTag(tag.id)' class="btn btn-sm btn-danger">
81+
<a href="javascript:;" data-ng-click='deleteTag(tag)' class="btn btn-sm btn-danger">
8282
<strong>Delete Tag</strong>
8383
</a></div>
8484
<div class="col-md-4 col-md-offset-4">
@@ -88,7 +88,7 @@
8888
</div>
8989
</div>
9090
</td>
91-
<td>{{showLabel(tag.status,tagStatuses)}}</td>
91+
<td>{{showLabel(tag.status,getTagStatuses(tag.domain))}}</td>
9292
</tr>
9393
</tbody>
9494
<tfoot>

src/app/tags/tags.new.controller.js

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.controller('NewTagCtrl', ['$rootScope','$scope', 'TagService', '$state',
2121
$scope.newTag.categories.push(c.value);
2222
});
2323

24-
$tagService.createTag($scope.newTag).then(function(){
24+
$tagService.createTagSync($scope.newTag).then(function(){
2525
$state.go('index.tags.list');
2626
},
2727
function(error) {

src/app/tags/tags.new.html

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ <h2>Details</h2>
3030
<div class="row">
3131
<div class="form-group col-md-2" ng-class="{'has-error': addForm.selectedTagStatus.$touched && addForm.selectedTagStatus.$invalid}">
3232
<label for="tag-status">Status</label>
33-
<select id="tag-status" class="form-control m-b" ng-options="tagStatus.value as tagStatus.name for tagStatus in tagStatuses" ng-model="newTag.status" name="selectedTagStatus">
33+
<select id="tag-status" class="form-control m-b" ng-options="tagStatus.value as tagStatus.name for tagStatus in getTagStatuses(newTag.domain)" ng-model="newTag.status" name="selectedTagStatus" required>
3434
</select>
3535
<div class="help-block" ng-messages="addForm.selectedTagStatus.$error" ng-show="addForm.selectedTagStatus.$touched">
3636
<div ng-messages-include="errorMessages.html"></div>

0 commit comments

Comments
 (0)