diff --git a/src/services/snippet.js b/src/services/snippet.js index 9268043a..09d9c367 100644 --- a/src/services/snippet.js +++ b/src/services/snippet.js @@ -22,9 +22,16 @@ angular.module('codexen.services') return $http.get(url) } + var destroy = function (id) { + var url = apiUrl + 'snippets/id/' + id + + return $http.delete(url) + } + return { findByUser: findByUser, create: create, - show: show + show: show, + delete: destroy } }) diff --git a/src/states/snippets/detail.js b/src/states/snippets/detail.js index b78b4b35..1145e3c4 100644 --- a/src/states/snippets/detail.js +++ b/src/states/snippets/detail.js @@ -1,6 +1,6 @@ /* global angular */ angular.module('codexen.states') - .controller('SnippetsDetailController', function (Snippet, $state) { + .controller('SnippetsDetailController', function (Snippet, $state, $rootScope) { var vm = this vm.isLoaded = false @@ -8,8 +8,16 @@ angular.module('codexen.states') var snippetId = $state.params.id Snippet.show(snippetId) - .success(function (data) { - vm.snippet = data.snippet - vm.isLoaded = true + .success(function (data) { + vm.snippet = data.snippet + vm.isLoaded = true + }) + + vm.delete = function () { + Snippet.delete(vm.snippet._id) + .success(function () { + $rootScope.$broadcast('snippetDeleted') + $state.go('snippets') }) + } }) diff --git a/src/states/snippets/detail.tpl.html b/src/states/snippets/detail.tpl.html index f053763c..deecb1e9 100644 --- a/src/states/snippets/detail.tpl.html +++ b/src/states/snippets/detail.tpl.html @@ -7,7 +7,7 @@ - + @@ -18,7 +18,7 @@
-

+

diff --git a/src/states/snippets/list.js b/src/states/snippets/list.js index 79c40dbe..5b650332 100644 --- a/src/states/snippets/list.js +++ b/src/states/snippets/list.js @@ -37,4 +37,8 @@ angular.module('codexen.states') laodSnippets() }) + $scope.$on('snippetDeleted', function () { + laodSnippets() + }) + }) diff --git a/src/states/snippets/list.tpl.html b/src/states/snippets/list.tpl.html index 517f2689..13dfe7a6 100644 --- a/src/states/snippets/list.tpl.html +++ b/src/states/snippets/list.tpl.html @@ -34,7 +34,7 @@

-

+

diff --git a/test.js b/test.js deleted file mode 100644 index 94dacead..00000000 --- a/test.js +++ /dev/null @@ -1,132 +0,0 @@ -var data = { - ABAP: ["abap"], - ABC: ["abc"], - ActionScript:["as"], - ADA: ["ada|adb"], - Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"], - AsciiDoc: ["asciidoc|adoc"], - Assembly_x86:["asm"], - AutoHotKey: ["ahk"], - BatchFile: ["bat|cmd"], - C9Search: ["c9search_results"], - C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp"], - Cirru: ["cirru|cr"], - Clojure: ["clj|cljs"], - Cobol: ["CBL|COB"], - coffee: ["coffee|cf|cson|^Cakefile"], - ColdFusion: ["cfm"], - CSharp: ["cs"], - CSS: ["css"], - Curly: ["curly"], - D: ["d|di"], - Dart: ["dart"], - Diff: ["diff|patch"], - Dockerfile: ["^Dockerfile"], - Dot: ["dot"], - Dummy: ["dummy"], - DummySyntax: ["dummy"], - Eiffel: ["e"], - EJS: ["ejs"], - Elixir: ["ex|exs"], - Elm: ["elm"], - Erlang: ["erl|hrl"], - Forth: ["frt|fs|ldr"], - FTL: ["ftl"], - Gcode: ["gcode"], - Gherkin: ["feature"], - Gitignore: ["^.gitignore"], - Glsl: ["glsl|frag|vert"], - golang: ["go"], - Groovy: ["groovy"], - HAML: ["haml"], - Handlebars: ["hbs|handlebars|tpl|mustache"], - Haskell: ["hs"], - haXe: ["hx"], - HTML: ["html|htm|xhtml"], - HTML_Ruby: ["erb|rhtml|html.erb"], - INI: ["ini|conf|cfg|prefs"], - Io: ["io"], - Jack: ["jack"], - Jade: ["jade"], - Java: ["java"], - JavaScript: ["js|jsm"], - JSON: ["json"], - JSONiq: ["jq"], - JSP: ["jsp"], - JSX: ["jsx"], - Julia: ["jl"], - LaTeX: ["tex|latex|ltx|bib"], - Lean: ["lean|hlean"], - LESS: ["less"], - Liquid: ["liquid"], - Lisp: ["lisp"], - LiveScript: ["ls"], - LogiQL: ["logic|lql"], - LSL: ["lsl"], - Lua: ["lua"], - LuaPage: ["lp"], - Lucene: ["lucene"], - Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"], - Markdown: ["md|markdown"], - Mask: ["mask"], - MATLAB: ["matlab"], - MEL: ["mel"], - MUSHCode: ["mc|mush"], - MySQL: ["mysql"], - Nix: ["nix"], - ObjectiveC: ["m|mm"], - OCaml: ["ml|mli"], - Pascal: ["pas|p"], - Perl: ["pl|pm"], - pgSQL: ["pgsql"], - PHP: ["php|phtml"], - Powershell: ["ps1"], - Praat: ["praat|praatscript|psc|proc"], - Prolog: ["plg|prolog"], - Properties: ["properties"], - Protobuf: ["proto"], - Python: ["py"], - R: ["r"], - RDoc: ["Rd"], - RHTML: ["Rhtml"], - Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"], - Rust: ["rs"], - SASS: ["sass"], - SCAD: ["scad"], - Scala: ["scala"], - Scheme: ["scm|rkt"], - SCSS: ["scss"], - SH: ["sh|bash|^.bashrc"], - SJS: ["sjs"], - Smarty: ["smarty|tpl"], - snippets: ["snippets"], - Soy_Template:["soy"], - Space: ["space"], - SQL: ["sql"], - SQLServer: ["sqlserver"], - Stylus: ["styl|stylus"], - SVG: ["svg"], - Tcl: ["tcl"], - Tex: ["tex"], - Text: ["txt"], - Textile: ["textile"], - Toml: ["toml"], - Twig: ["twig"], - Typescript: ["ts|typescript|str"], - Vala: ["vala"], - VBScript: ["vbs|vb"], - Velocity: ["vm"], - Verilog: ["v|vh|sv|svh"], - VHDL: ["vhd|vhdl"], - XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl|xaml"], - XQuery: ["xq"], - YAML: ["yaml|yml"], - Django: ["html"] -} -var arr = [] - -for(var key in data){ - arr.push({name:key, mode:data[key]}) -} - -console.log(JSON.stringify(arr, null, ' '))