From f2ae23b1b44d2e40cbfa2627e2ac93affa1cdba8 Mon Sep 17 00:00:00 2001 From: Allen Bargi Date: Mon, 24 Feb 2014 10:48:49 +0100 Subject: [PATCH] bringing back the save feature --- TODO.todo | 11 ++++------- app/assets/js/controllers/editor_controller.coffee | 8 +++++++- app/assets/js/services/file_manager_service.coffee | 10 ++++++++++ app/assets/js/services/theme_service.coffee | 3 +++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/TODO.todo b/TODO.todo index 6c90e255..0db61e2a 100644 --- a/TODO.todo +++ b/TODO.todo @@ -1,15 +1,9 @@ TODO v.0.7: - ☐ BUG: save does not work (gallery/local/external) - ☐ slide animation is not smooth - ☐ add more themes - ☐ more lang support (PHP Perl GO LESS SCSS C C++ Lua XML Markdown Latex) - -Preview and scope bar: ☐ do not scroll preview when popover is open on the preview code - ☐ refactor scopebar Refactor: ☐ refactor routing + ☐ refactor scopebar Performance: ☐ cache gallery, color-schemes and file samples locally to boost speed (https://github.com/jmdobry/angular-cache) @@ -25,6 +19,8 @@ BackEnds: ☐ https://developers.goinstant.com/v1/GoAngular/index.html TODO: + ☐ add more themes + ☐ more lang support (PHP Perl GO LESS SCSS C C++ Lua XML Markdown Latex) ☐ confirm delete local themes ☐ rss feed for gallery ☐ contrast score for bg and fg https://github.com/LeaVerou/contrast-ratio @@ -136,6 +132,7 @@ Test: ☐ download theme ___________________ Archive: + ✔ BUG: save does not work (gallery/local/external) @done (14-02-24 10:42) @project(TODO v.0.7) ✔ BUG: back when galerry is closed -> badly posisioned throbber @done (14-02-24 10:04) ✔ gutter issue (redo gutter styling) @done (14-02-24 09:48) @project(Preview and scope bar) ✔ dynamically set pre width based on longest line @done (14-02-24 09:48) @project(Preview and scope bar) diff --git a/app/assets/js/controllers/editor_controller.coffee b/app/assets/js/controllers/editor_controller.coffee index a63fa5be..c9811683 100644 --- a/app/assets/js/controllers/editor_controller.coffee +++ b/app/assets/js/controllers/editor_controller.coffee @@ -155,8 +155,14 @@ Application.controller 'editorController', # -- SAVE --------------------------------------------------- - # TODO: this is broken $scope.save_theme = -> + return unless Theme.json + if Theme.type == 'Local File' + FileManager.save($scope.selected_theme, Theme.to_plist()) + else + # save a local copy of current theme + FileManager.add_from_memory($scope.selected_theme, Theme.to_plist()) + $location.path("/local/#{$scope.selected_theme}") # -- ROUTING ---------------------------------------------- # TODO: make this a proper angular routing diff --git a/app/assets/js/services/file_manager_service.coffee b/app/assets/js/services/file_manager_service.coffee index c11734d1..566acf29 100644 --- a/app/assets/js/services/file_manager_service.coffee +++ b/app/assets/js/services/file_manager_service.coffee @@ -25,6 +25,14 @@ Application.factory "FileManager", ['$q', ($q) -> localStorage.setItem("local_files", angular.toJson(@list)) file_names + add_from_memory = (file_name, content) -> + @list.push({name: file_name}) + localStorage.setItem("local_files", angular.toJson(@list)) + @save(file_name, content) + + save = (file_name, content) -> + localStorage.setItem("THEME/#{file_name}", content) + remove = (file) -> @list.remove(file) localStorage.setItem("local_files", angular.toJson(@list)) @@ -34,6 +42,8 @@ Application.factory "FileManager", ['$q', ($q) -> list: list add: add load: load + save: save remove: remove + add_from_memory: add_from_memory } ] diff --git a/app/assets/js/services/theme_service.coffee b/app/assets/js/services/theme_service.coffee index d871aab6..5cd2ee38 100644 --- a/app/assets/js/services/theme_service.coffee +++ b/app/assets/js/services/theme_service.coffee @@ -55,6 +55,8 @@ Application.factory "Theme", ['Color', 'json_to_plist', 'plist_to_json', (Color, blob = new Blob([plist], {type: 'text/plain'}) saveAs blob, "#{@json.name}.tmTheme" + to_plist = -> json_to_plist(@json) + # Theme Stylesheet Generator ------------------------------------------ css_scopes = -> @@ -101,6 +103,7 @@ Application.factory "Theme", ['Color', 'json_to_plist', 'plist_to_json', (Color, { process: process download: download + to_plist: to_plist xml: xml json: json type: type