mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
refactor update/create behaviors
This commit is contained in:
@@ -5,22 +5,19 @@ angular.module('codexen')
|
||||
|
||||
vm.aceModes = aceModes
|
||||
vm.snippet = snippet
|
||||
console.log(snippet)
|
||||
|
||||
vm.submit = function () {
|
||||
console.log('mode: ', vm.snippet.mode)
|
||||
var params = {
|
||||
description: vm.snippet.description,
|
||||
callSign: vm.snippet.callSign,
|
||||
mode: vm.snippet.mode == null ? null : vm.snippet.mode.toLowerCase(),
|
||||
content: vm.snippet.content,
|
||||
tags: angular.isArray(vm.snippet.tags) ? vm.snippet.tags.map(function (tag) { return tag.name }) : []
|
||||
Tags: angular.isArray(vm.snippet.Tags) ? vm.snippet.Tags.map(function (tag) { return tag.name }) : []
|
||||
}
|
||||
|
||||
Snippet.update(vm.snippet._id, params)
|
||||
Snippet.update(vm.snippet.id, params)
|
||||
.success(function (data) {
|
||||
console.log('updated res :', data)
|
||||
$modalInstance.close(data)
|
||||
console.log('snippet created!', data)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -31,12 +28,12 @@ angular.module('codexen')
|
||||
return Tag.findByName(tagName)
|
||||
.success(function (data) {
|
||||
console.log('tags fetched!!', data)
|
||||
vm.tagCandidates = data.tags
|
||||
vm.tagCandidates = data
|
||||
})
|
||||
}
|
||||
vm.transform = function (tagName) {
|
||||
return {
|
||||
_id: 0,
|
||||
id: 0,
|
||||
name: tagName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ angular.module('codexen')
|
||||
callSign: vm.callSign,
|
||||
mode: vm.mode == null ? null : vm.mode.toLowerCase(),
|
||||
content: vm.content,
|
||||
tags: angular.isArray(vm.tags) ? vm.tags.map(function (tag) { return tag.name }) : []
|
||||
tags: angular.isArray(vm.Tags) ? vm.Tags.map(function (tag) { return tag.name }) : []
|
||||
}
|
||||
|
||||
Snippet.create(params)
|
||||
@@ -27,12 +27,12 @@ angular.module('codexen')
|
||||
return Tag.findByName(tagName)
|
||||
.success(function (data) {
|
||||
console.log('tags fetched!!', data)
|
||||
vm.tagCandidates = data.tags
|
||||
vm.tagCandidates = data
|
||||
})
|
||||
}
|
||||
vm.transform = function (tagName) {
|
||||
return {
|
||||
_id: 0,
|
||||
id: 0,
|
||||
name: tagName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* global angular */
|
||||
angular.module('codexen')
|
||||
.controller('SnippetsDetailController', function (Snippet, $state, $rootScope) {
|
||||
.controller('SnippetsDetailController', function (Snippet, $state, $rootScope, $scope) {
|
||||
var vm = this
|
||||
|
||||
vm.isLoaded = false
|
||||
@@ -23,4 +23,9 @@ angular.module('codexen')
|
||||
$rootScope.$broadcast('snippetDeleted')
|
||||
})
|
||||
}
|
||||
|
||||
$scope.$on('snippetUpdated', function (e, snippet) {
|
||||
console.log('event received', snippet)
|
||||
if (snippet.id === vm.snippet.id) vm.snippet = snippet
|
||||
})
|
||||
})
|
||||
|
||||
@@ -34,7 +34,7 @@ angular.module('codexen')
|
||||
})
|
||||
|
||||
$scope.$on('snippetUpdated', function (e, snippet) {
|
||||
$state.go('snippets.detail', {id: snippet._id})
|
||||
$state.go('snippets.detail', {id: snippet.id})
|
||||
loadSnippets()
|
||||
})
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ angular.module('codexen')
|
||||
el.on('click', function () {
|
||||
Modal.newSnippet()
|
||||
.result.then(function (snippet) {
|
||||
console.log('event fire', snippet)
|
||||
$rootScope.$broadcast('snippetUpdated', snippet)
|
||||
}, function () {
|
||||
console.log('new snippet modal dismissed')
|
||||
|
||||
@@ -32,7 +32,4 @@
|
||||
<li ui-sref-active="active">
|
||||
<a ui-sref="snippets"><i class="fa fa-code"></i> Snippets</a>
|
||||
</li>
|
||||
<li ui-sref-active="active">
|
||||
<a><i class="fa fa-paperclip"></i> Clips(ready)</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -31,10 +31,10 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<ui-select multiple tagging="vm.transform" tagging-tokens="SPACE|,|/" ng-model="vm.tags" theme="bootstrap">
|
||||
<ui-select multiple tagging="vm.transform" tagging-tokens="SPACE|,|/" ng-model="vm.Tags" theme="bootstrap">
|
||||
<ui-select-match placeholder="Tags...">{{$item.name}}</ui-select-match>
|
||||
<ui-select-choices repeat="tag in vm.tagCandidates" refresh="vm.refreshTagCandidates($select.search)"
|
||||
refresh-delay="200">
|
||||
refresh-delay="100">
|
||||
<div><span ng-bind-html="tag.name | highlight: $select.search"></span><span ng-if="tag.isTag">(new)</span></div>
|
||||
</ui-select-choices>
|
||||
</ui-select>
|
||||
|
||||
Reference in New Issue
Block a user