mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 18:26:26 +00:00
add Recipes(scaffolding)
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
/* global angular */
|
||||
angular.module('codexen')
|
||||
.controller('SnippetsListController', function ($auth, Snippet, $scope, $state, $scope, $filter, mySnippets, User) {
|
||||
.controller('SnippetsListController', function ($auth, Snippet, $scope, $state, $filter, mySnippets, User) {
|
||||
var vm = this
|
||||
|
||||
vm.isLoading = false
|
||||
|
||||
vm.snippetId = parseInt($state.params.id)
|
||||
|
||||
vm.snippets = mySnippets
|
||||
@@ -33,14 +31,13 @@ angular.module('codexen')
|
||||
$scope.$on('$stateChangeSuccess', function (e, toState, toParams) {
|
||||
if (!toState.name.match(/snippets/)) return null
|
||||
|
||||
vm.snippetId = parseInt(toParams.id)
|
||||
vm.snippetId = parseInt(toParams.id, 10)
|
||||
|
||||
if (!vm.snippetId && vm.filtered[0]) {
|
||||
$state.go('snippets.detail', {id: vm.filtered[0].id})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
$scope.$on('snippetUpdated', function (e, snippet) {
|
||||
if (!mySnippets.some(function (_snippet, index) {
|
||||
if (_snippet.id === snippet.id) {
|
||||
@@ -57,7 +54,7 @@ angular.module('codexen')
|
||||
|
||||
$scope.$on('snippetDeleted', function () {
|
||||
if ($state.is('snippets.detail')) {
|
||||
var currentSnippetId = parseInt($state.params.id)
|
||||
var currentSnippetId = parseInt($state.params.id, 10)
|
||||
// Delete snippet from snippet list
|
||||
for (var i = 0; i < vm.snippets.length; i++) {
|
||||
if (vm.snippets[i].id === currentSnippetId) {
|
||||
@@ -67,10 +64,10 @@ angular.module('codexen')
|
||||
}
|
||||
// Delete snippet from `filtered list`
|
||||
// And redirect `next filtered snippet`
|
||||
for (var i = 0; i < vm.filtered.length; i++) {
|
||||
for (i = 0; i < vm.filtered.length; i++) {
|
||||
if (vm.filtered[i].id === currentSnippetId) {
|
||||
if (vm.filtered[i+1] != null) $state.go('snippets.detail', {id: vm.filtered[i+1].id})
|
||||
else if (vm.filtered[i-1] != null) $state.go('snippets.detail', {id: vm.filtered[i-1].id})
|
||||
if (vm.filtered[i + 1] != null) $state.go('snippets.detail', {id: vm.filtered[i + 1].id})
|
||||
else if (vm.filtered[i - 1] != null) $state.go('snippets.detail', {id: vm.filtered[i - 1].id})
|
||||
else $state.go('snippets')
|
||||
|
||||
vm.filtered.splice(i, 1)
|
||||
@@ -100,7 +97,7 @@ angular.module('codexen')
|
||||
}
|
||||
}
|
||||
|
||||
function searchSnippets() {
|
||||
function searchSnippets () {
|
||||
vm.filtered = $filter('searchSnippets')(mySnippets, vm.search)
|
||||
if (vm.search && vm.filtered[0] && (!vm.snippetId || vm.snippetId !== vm.filtered[0].id)) {
|
||||
$state.go('snippets.detail', {id: vm.filtered[0].id})
|
||||
|
||||
Reference in New Issue
Block a user