1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

improve snippets.list UX & add instant edit handler for snippet with empty tag-list

This commit is contained in:
Rokt33r
2015-06-11 04:10:01 +09:00
parent 9762da28a4
commit c81bddad2a
6 changed files with 61 additions and 6 deletions

View File

@@ -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

View File

@@ -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 () {

View File

@@ -0,0 +1,24 @@
/* global angular */
angular.module('codexen')
.directive('snippetItem', function (Modal, $rootScope) {
return {
restrict: 'A',
transclude: true,
template: '<div ng-transclude></div>',
scope: {
snippet: '=snippetItem'
},
link: function (scope, elem) {
scope.$on('taggingRequested', function (e) {
e.stopPropagation()
e.preventDefault()
Modal.editSnippet(angular.copy(scope.snippet))
.result.then(function (snippet) {
$rootScope.$broadcast('snippetUpdated', snippet)
}, function () {
console.log('edit snippet modal dismissed')
})
})
}
}
})

View File

@@ -3,9 +3,10 @@ angular.module('codexen')
.directive('tagList', function () {
return {
restrict: 'A',
template: '<p class="tags" ng-if="tags.length">' +
template: '<p class="tags">' +
'<i class="fa fa-tags"></i> ' +
'<a tag-item="tag" ng-repeat="tag in tags" href></a>' +
'<a ng-if="!tags.length" ng-click="requestTagging($event)" href> Not tagged yet</a>' +
'</p>',
scope: {
tags: '=tagList'
@@ -16,6 +17,12 @@ angular.module('codexen')
e.stopPropagation()
})
})
scope.requestTagging = function (e) {
e.preventDefault()
e.stopPropagation()
scope.$emit('taggingRequested')
}
}
}
})

View File

@@ -13,7 +13,7 @@
<ui-select ng-model="vm.mode" style="display: inline-block;" on-select="vm.log(vm.mode.name.toLowerCase())" theme="bootstrap">
<ui-select-match placeholder="Select Type">{{$select.selected}}</ui-select-match>
<ui-select-choices repeat="mode in vm.aceModes | filter: $select.search">
<div ng-bind-html="mode | highlight: $select.search"></div>
<div ng-bind="::mode"></div>
</ui-select-choices>
</ui-select>
</div>

View File

@@ -26,7 +26,7 @@
<a ui-sref="auth.signin" class="btn btn-default"><i class="fa fa-signin"></i> Sign In</a>
</li>
<li ng-repeat="snippet in vm.filtered" ui-sref="snippets.detail({id:snippet.id})" ng-class="{active:vm.snippetId===snippet.id}">
<li snippet-item="snippet" ng-repeat="snippet in vm.filtered" ui-sref="snippets.detail({id:snippet.id})" ng-class="{active:vm.snippetId===snippet.id}">
<div class="media">
<div class="media-left">
<img width="25" height="25" class="img-circle" src="http://www.gravatar.com/avatar/ea0b6ad1c11700120d1af08810caa19d" alt="" />