Skip to content

Commit 68956ec

Browse files
committed
refactor update/create behaviors
1 parent f1adb97 commit 68956ec

7 files changed

Lines changed: 17 additions & 19 deletions

File tree

src/controllers/modals/EditSnippetModalController.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ angular.module('codexen')
55

66
vm.aceModes = aceModes
77
vm.snippet = snippet
8-
console.log(snippet)
98

109
vm.submit = function () {
11-
console.log('mode: ', vm.snippet.mode)
1210
var params = {
1311
description: vm.snippet.description,
1412
callSign: vm.snippet.callSign,
1513
mode: vm.snippet.mode == null ? null : vm.snippet.mode.toLowerCase(),
1614
content: vm.snippet.content,
17-
tags: angular.isArray(vm.snippet.tags) ? vm.snippet.tags.map(function (tag) { return tag.name }) : []
15+
Tags: angular.isArray(vm.snippet.Tags) ? vm.snippet.Tags.map(function (tag) { return tag.name }) : []
1816
}
19-
20-
Snippet.update(vm.snippet._id, params)
17+
Snippet.update(vm.snippet.id, params)
2118
.success(function (data) {
19+
console.log('updated res :', data)
2220
$modalInstance.close(data)
23-
console.log('snippet created!', data)
2421
})
2522
}
2623

@@ -31,12 +28,12 @@ angular.module('codexen')
3128
return Tag.findByName(tagName)
3229
.success(function (data) {
3330
console.log('tags fetched!!', data)
34-
vm.tagCandidates = data.tags
31+
vm.tagCandidates = data
3532
})
3633
}
3734
vm.transform = function (tagName) {
3835
return {
39-
_id: 0,
36+
id: 0,
4037
name: tagName
4138
}
4239
}

src/controllers/modals/NewSnippetModalController.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ angular.module('codexen')
1111
callSign: vm.callSign,
1212
mode: vm.mode == null ? null : vm.mode.toLowerCase(),
1313
content: vm.content,
14-
tags: angular.isArray(vm.tags) ? vm.tags.map(function (tag) { return tag.name }) : []
14+
tags: angular.isArray(vm.Tags) ? vm.Tags.map(function (tag) { return tag.name }) : []
1515
}
1616

1717
Snippet.create(params)
@@ -27,12 +27,12 @@ angular.module('codexen')
2727
return Tag.findByName(tagName)
2828
.success(function (data) {
2929
console.log('tags fetched!!', data)
30-
vm.tagCandidates = data.tags
30+
vm.tagCandidates = data
3131
})
3232
}
3333
vm.transform = function (tagName) {
3434
return {
35-
_id: 0,
35+
id: 0,
3636
name: tagName
3737
}
3838
}

src/controllers/states/SnippetsDetailController.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global angular */
22
angular.module('codexen')
3-
.controller('SnippetsDetailController', function (Snippet, $state, $rootScope) {
3+
.controller('SnippetsDetailController', function (Snippet, $state, $rootScope, $scope) {
44
var vm = this
55

66
vm.isLoaded = false
@@ -23,4 +23,9 @@ angular.module('codexen')
2323
$rootScope.$broadcast('snippetDeleted')
2424
})
2525
}
26+
27+
$scope.$on('snippetUpdated', function (e, snippet) {
28+
console.log('event received', snippet)
29+
if (snippet.id === vm.snippet.id) vm.snippet = snippet
30+
})
2631
})

src/controllers/states/SnippetsListController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ angular.module('codexen')
3434
})
3535

3636
$scope.$on('snippetUpdated', function (e, snippet) {
37-
$state.go('snippets.detail', {id: snippet._id})
37+
$state.go('snippets.detail', {id: snippet.id})
3838
loadSnippets()
3939
})
4040

src/directives/btn-new-snippet.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ angular.module('codexen')
66
el.on('click', function () {
77
Modal.newSnippet()
88
.result.then(function (snippet) {
9-
console.log('event fire', snippet)
109
$rootScope.$broadcast('snippetUpdated', snippet)
1110
}, function () {
1211
console.log('new snippet modal dismissed')

src/tpls/directives/side-nav.tpl.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,4 @@
3232
<li ui-sref-active="active">
3333
<a ui-sref="snippets"><i class="fa fa-code"></i> Snippets</a>
3434
</li>
35-
<li ui-sref-active="active">
36-
<a><i class="fa fa-paperclip"></i> Clips(ready)</a>
37-
</li>
3835
</ul>

src/tpls/modals/new-snippet-modal.tpl.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ <h4>New Snippet</h4>
3131
</div>
3232

3333
<div class="form-group">
34-
<ui-select multiple tagging="vm.transform" tagging-tokens="SPACE|,|/" ng-model="vm.tags" theme="bootstrap">
34+
<ui-select multiple tagging="vm.transform" tagging-tokens="SPACE|,|/" ng-model="vm.Tags" theme="bootstrap">
3535
<ui-select-match placeholder="Tags...">{{$item.name}}</ui-select-match>
3636
<ui-select-choices repeat="tag in vm.tagCandidates" refresh="vm.refreshTagCandidates($select.search)"
37-
refresh-delay="200">
37+
refresh-delay="100">
3838
<div><span ng-bind-html="tag.name | highlight: $select.search"></span><span ng-if="tag.isTag">(new)</span></div>
3939
</ui-select-choices>
4040
</ui-select>

0 commit comments

Comments
 (0)