From ab507dc16583c047dbd47da75fd4d8769f8657ea Mon Sep 17 00:00:00 2001 From: did Date: Tue, 24 Jan 2012 21:16:53 +0100 Subject: [PATCH] change the default API base path + implement the API for content_assets, content_types and pages resources --- .../content_types/custom_fields_view.coffee | 8 ++++-- .../api/content_assets_controller.rb | 23 +++++++++++++++ .../api/content_types_controller.rb | 28 +++++++++++++++++++ .../locomotive/api/pages_controller.rb | 25 +++++++++++++++++ .../locomotive/api/snippets_controller.rb | 8 ++---- .../locomotive/api/theme_assets_controller.rb | 6 ++-- .../locomotive/api/tokens_controller.rb | 4 --- config/routes.rb | 11 ++++++-- doc/TODO | 25 +++++++++++------ 9 files changed, 111 insertions(+), 27 deletions(-) create mode 100644 app/controllers/locomotive/api/content_assets_controller.rb create mode 100644 app/controllers/locomotive/api/content_types_controller.rb create mode 100644 app/controllers/locomotive/api/pages_controller.rb diff --git a/app/assets/javascripts/locomotive/views/content_types/custom_fields_view.coffee b/app/assets/javascripts/locomotive/views/content_types/custom_fields_view.coffee index 545985b3..8a73064f 100644 --- a/app/assets/javascripts/locomotive/views/content_types/custom_fields_view.coffee +++ b/app/assets/javascripts/locomotive/views/content_types/custom_fields_view.coffee @@ -66,12 +66,16 @@ class Locomotive.Views.ContentTypes.CustomFieldsView extends Backbone.View @add_entry(event) remove_entry: (custom_field, view) -> + if custom_field.isNew() + @model.get('entries_custom_fields').remove(custom_field) + else + custom_field.set _destroy: true + @_entry_views = _.reject @_entry_views, (_view) -> _view == view - @model.get('entries_custom_fields').remove(custom_field) @refresh_position_entries() - @$('> .empty').show() if @model.get('entries_custom_fields').length == 0 + @$('> .empty').show() if @_entry_views.length == 0 render_entries: -> if @model.get('entries_custom_fields').length == 0 diff --git a/app/controllers/locomotive/api/content_assets_controller.rb b/app/controllers/locomotive/api/content_assets_controller.rb new file mode 100644 index 00000000..00296527 --- /dev/null +++ b/app/controllers/locomotive/api/content_assets_controller.rb @@ -0,0 +1,23 @@ +module Locomotive + module Api + class ContentAssetsController < BaseController + + def index + @content_assets = current_site.content_assets + respond_with(@content_assets) + end + + def create + @content_asset = current_site.content_assets.create(params[:content_asset]) + respond_with @content_asset, :location => locomotive_api_content_asset_url(@content_asset._id) + end + + def update + @content_asset = current_site.content_assets.find(params[:id]) + @content_asset.update_attributes(params[:content_asset]) + respond_with @content_asset, :location => locomotive_api_content_asset_url(@content_asset._id) + end + + end + end +end diff --git a/app/controllers/locomotive/api/content_types_controller.rb b/app/controllers/locomotive/api/content_types_controller.rb new file mode 100644 index 00000000..a58838b4 --- /dev/null +++ b/app/controllers/locomotive/api/content_types_controller.rb @@ -0,0 +1,28 @@ +module Locomotive + module Api + class ContentTypesController < BaseController + + def index + @content_types = current_site.content_types + respond_with(@content_types) + end + + def create + @content_type = current_site.content_types.create(params[:content_type]) + respond_with @content_type, :location => edit_locomotive_api_content_type_url(@content_type._id) + end + + def edit + @content_type = current_site.content_types.find(params[:id]) + respond_with @content_type + end + + def update + @content_type = current_site.content_types.find(params[:id]) + @content_type.update_attributes(params[:content_type]) + respond_with @content_type, :location => edit_locomotive_api_content_type_url(@content_type._id) + end + + end + end +end diff --git a/app/controllers/locomotive/api/pages_controller.rb b/app/controllers/locomotive/api/pages_controller.rb new file mode 100644 index 00000000..dea546c4 --- /dev/null +++ b/app/controllers/locomotive/api/pages_controller.rb @@ -0,0 +1,25 @@ +module Locomotive + module Api + class PagesController < BaseController + + def index + @pages = current_site.pages.all + respond_with(@pages) + end + + def create + @page = current_site.pages.create(params[:page]) + respond_with @page, :location => edit_locomotive_api_page_url(@page._id) + end + + def update + @page = current_site.pages.find(params[:id]) + @page.update_attributes(params[:page]) + respond_with @page, :location => edit_locomotive_api_page_url(@page._id) + end + + end + + end +end + diff --git a/app/controllers/locomotive/api/snippets_controller.rb b/app/controllers/locomotive/api/snippets_controller.rb index ba2ab841..110ccf84 100644 --- a/app/controllers/locomotive/api/snippets_controller.rb +++ b/app/controllers/locomotive/api/snippets_controller.rb @@ -1,10 +1,7 @@ module Locomotive module Api - class SnippetsController < BaseController - include Locomotive::Routing::SiteDispatcher - def index @snippets = current_site.snippets.all respond_with(@snippets) @@ -12,17 +9,16 @@ module Locomotive def create @snippet = current_site.snippets.create(params[:snippet]) - respond_with @snippet, :location => edit_snippet_url(@snippet._id) + respond_with @snippet, :location => edit_locomotive_api_snippet_url(@snippet._id) end def update @snippet = current_site.snippets.find(params[:id]) @snippet.update_attributes(params[:snippet]) - respond_with @snippet, :location => edit_snippet_url(@snippet._id) + respond_with @snippet, :location => edit_locomotive_api_snippet_url(@snippet._id) end end - end end diff --git a/app/controllers/locomotive/api/theme_assets_controller.rb b/app/controllers/locomotive/api/theme_assets_controller.rb index a7509310..de8d29f6 100644 --- a/app/controllers/locomotive/api/theme_assets_controller.rb +++ b/app/controllers/locomotive/api/theme_assets_controller.rb @@ -2,8 +2,6 @@ module Locomotive module Api class ThemeAssetsController < BaseController - include Locomotive::Routing::SiteDispatcher - def index @theme_assets = current_site.theme_assets.all respond_with(@theme_assets) @@ -11,13 +9,13 @@ module Locomotive def create @theme_asset = current_site.theme_assets.create(params[:theme_asset]) - respond_with @theme_asset, :location => edit_theme_asset_url(@theme_asset._id) + respond_with @theme_asset, :location => edit_locomotive_api_theme_asset_url(@theme_asset._id) end def update @theme_asset = current_site.theme_assets.find(params[:id]) @theme_asset.update_attributes(params[:theme_asset]) - respond_with @theme_asset, :location => edit_theme_asset_url(@theme_asset._id) + respond_with @theme_asset, :location => edit_locomotive_api_theme_asset_url(@theme_asset._id) end end diff --git a/app/controllers/locomotive/api/tokens_controller.rb b/app/controllers/locomotive/api/tokens_controller.rb index 501eb2aa..637fd2d0 100644 --- a/app/controllers/locomotive/api/tokens_controller.rb +++ b/app/controllers/locomotive/api/tokens_controller.rb @@ -23,9 +23,5 @@ module Locomotive end end - end - end - -# cAEERKkstnUya7UVxkqN \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 87b2c53e..3e1b77cf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,6 +41,7 @@ Locomotive::Engine.routes.draw do put :sort, :on => :collection end + # TODO resources :custom_fields, :path => 'custom/:parent/:slug/fields' resources :cross_domain_sessions, :only => [:new, :create] @@ -57,18 +58,22 @@ end Rails.application.routes.draw do - # api - namespace :_locomotive, :module => 'locomotive' do - namespace :api do + # API + namespace :locomotive, :module => 'locomotive' do + namespace :api do resources :tokens, :only => [:create, :destroy] resources :theme_assets + resources :content_assets + resources :snippets resources :pages + resources :content_types + end end diff --git a/doc/TODO b/doc/TODO index 9202e6a8..31447fc0 100644 --- a/doc/TODO +++ b/doc/TODO @@ -87,20 +87,29 @@ x deployment x fix integration problems x pre-compile assets - API - - authentication from a token + controller to deliver a token - - api routes - - add a way to custom the as_json method within the presenters (by default as_json ?) + custom responder ? + x authentication from a token + controller to deliver a token + x api routes + x change api location + (- add a way to custom the as_json method within the presenters (by default as_json ?) + custom responder ?) - REST actions: - - CRUD assets - - CRUD pages - - CRUD snippets - - CRUD content types + x CRUD theme assets + x CRUD snippets + x CRUD content assets + x CRUD pages + x CRUD content types - data ? +- refactoring + - remove the import / export scripts + - remove the cross domain authentication (use auth_token instead) +- upgrade to rails 3.2 (https://github.com/locomotivecms/engine/pull/281/files) - bugs: x unable to toggle the "required" check_boxes for content types x unable to sign out - - https://github.com/locomotivecms/engine/pull/281/files + x unable to remove a field + + - "back to admin" link does not work if inline editor disabled + - disallow to click twice on the submit form button (spinner ?) - message to notify people if their browser is too old