mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-25 23:51:51 +00:00
improve snippets.list UX & add instant edit handler for snippet with empty tag-list
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* global angular */
|
||||
angular.module('codexen')
|
||||
.controller('SnippetsDetailController', function (Snippet, $state, $rootScope, $scope) {
|
||||
.controller('SnippetsDetailController', function (Snippet, $state, $rootScope, $scope, Modal) {
|
||||
var vm = this
|
||||
|
||||
vm.isLoaded = false
|
||||
@@ -24,6 +24,18 @@ angular.module('codexen')
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
$scope.$on('taggingRequested', function (e) {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
Modal.editSnippet(angular.copy(vm.snippet))
|
||||
.result.then(function (snippet) {
|
||||
$rootScope.$broadcast('snippetUpdated', snippet)
|
||||
}, function () {
|
||||
console.log('edit snippet modal dismissed')
|
||||
})
|
||||
})
|
||||
|
||||
$scope.$on('snippetUpdated', function (e, snippet) {
|
||||
console.log('event received', snippet)
|
||||
if (snippet.id === vm.snippet.id) vm.snippet = snippet
|
||||
|
||||
@@ -20,8 +20,11 @@ angular.module('codexen')
|
||||
|
||||
// TODO: keyboard navigating UX
|
||||
|
||||
$scope.$on('$stateChangeStart', function (e, toState, toParams) {
|
||||
$scope.$on('$stateChangeSuccess', function (e, toState, toParams) {
|
||||
if (!toState.name.match(/snippets/)) return null
|
||||
|
||||
vm.snippetId = parseInt(toParams.id)
|
||||
|
||||
if (!vm.snippetId && vm.filtered[0]) {
|
||||
$state.go('snippets.detail', {id: vm.filtered[0].id})
|
||||
}
|
||||
@@ -29,8 +32,17 @@ angular.module('codexen')
|
||||
|
||||
|
||||
$scope.$on('snippetUpdated', function (e, snippet) {
|
||||
if (!mySnippets.some(function (_snippet, index) {
|
||||
if (_snippet.id === snippet.id) {
|
||||
mySnippets[index] = snippet
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})) mySnippets.unshift(snippet)
|
||||
|
||||
searchSnippets()
|
||||
vm.snippetId = snippet.id
|
||||
$state.go('snippets.detail', {id: snippet.id})
|
||||
loadSnippets()
|
||||
})
|
||||
|
||||
$scope.$on('snippetDeleted', function () {
|
||||
|
||||
Reference in New Issue
Block a user