From 40e007de8539d9424c90dccd20122daebf80f9cc Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 2 Dec 2014 20:21:20 +0800 Subject: [PATCH] category and tags added and also edit page --- .../admin/registered_sites_controller.rb | 33 ++++- app/models/registered_site.rb | 8 ++ .../admin/registered_sites/_form.html.erb | 123 ++++++++++++++++++ .../admin/registered_sites/_index.html.erb | 25 +++- .../admin/registered_sites/edit.html.erb | 6 + lib/registered_sites/engine.rb | 10 ++ 6 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 app/views/admin/registered_sites/_form.html.erb create mode 100644 app/views/admin/registered_sites/edit.html.erb diff --git a/app/controllers/admin/registered_sites_controller.rb b/app/controllers/admin/registered_sites_controller.rb index 769d1bb..16a0f31 100644 --- a/app/controllers/admin/registered_sites_controller.rb +++ b/app/controllers/admin/registered_sites_controller.rb @@ -1,16 +1,37 @@ # encoding: utf-8 class Admin::RegisteredSitesController < OrbitAdminController + before_action ->(module_app = @app_title) { set_variables module_app } def index - @registeredsites = RegisteredSite.all + @registeredsites = RegisteredSite.all.order_by(sort) + .with_categories(filters("category")) + .with_tags(filters("tag")) @table_fields = table_fields - @filter_fields = {} - @registeredsites = @registeredsites.page(params[:page]).per(10) + @tags = @module_app.tags + @categories = @module_app.categories.enabled + @filter_fields = filter_fields_without_status(@categories, @tags) + @registeredsites = search_data(@registeredsites,[:title]).page(params[:page]).per(10) if request.xhr? render :partial => "index" end end + def edit + @registered_site = RegisteredSite.find(params[:id]) + if can_edit_or_delete?(@registered_site) + else + render_401 + end + end + + def update + uid = params[:id].split('-').last + registered_site = RegisteredSite.find_by(:uid => uid) + registered_site.update_attributes(registered_site_params) + registered_site.save + redirect_to params['referer_url'] + end + def change_access_status status = params[:status] site = RegisteredSite.find_by(:uid => params[:uid]) @@ -29,6 +50,10 @@ class Admin::RegisteredSitesController < OrbitAdminController private def table_fields - [:domain, :admin_email, :status, :permission] + [:domain, :admin_email, :status, :category, :tags, :permission] + end + + def registered_site_params + params.require(:registered_site).permit! end end \ No newline at end of file diff --git a/app/models/registered_site.rb b/app/models/registered_site.rb index a183bda..06a7ee9 100644 --- a/app/models/registered_site.rb +++ b/app/models/registered_site.rb @@ -1,9 +1,13 @@ class RegisteredSite include Mongoid::Document include Mongoid::Timestamps + include OrbitTag::Taggable + include OrbitCategory::Categorizable include Slug field :site_domain + field :title, as: :slug_title, localize: true + field :description, localize: true field :access_granted, type: Boolean, :default => false field :admin_email field :site_confirmed, type: Boolean, :default => false @@ -20,4 +24,8 @@ class RegisteredSite self.save end + def active? + return self.access_granted && self.site_confirmed + end + end \ No newline at end of file diff --git a/app/views/admin/registered_sites/_form.html.erb b/app/views/admin/registered_sites/_form.html.erb new file mode 100644 index 0000000..e508746 --- /dev/null +++ b/app/views/admin/registered_sites/_form.html.erb @@ -0,0 +1,123 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> + + +
+ + + + + + +
+ + +
+ + +
+ + +
+ + +
+ +
+ <%= select_category(f, @module_app) %> +
+
+ + +
+ +
+ <%= f.text_field :admin_email %> +
+
+ +
+ + +
+
+ + <%= select_tags(f, @module_app) %> +
+
+ +
+ + + + + + +
+ + <% @site_in_use_locales.each_with_index do |locale, i| %> + +
"> + + +
+ +
+ <%= f.fields_for :title_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t(:title), value: (@registered_site.title_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+
+ <%= f.fields_for :description_translations do |f| %> + <%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@registered_site.description_translations[locale] rescue nil) %> + <% end %> +
+
+
+ +
+ + <% end %> + +
+ +
+ + +
+ <%= get_referer_url[:action] rescue "" %> + <%= f.submit t('submit'), class: 'btn btn-primary' %> + + <%= link_to t('cancel'), admin_registered_sites_path, :class=>"btn" %> +
+ + + + diff --git a/app/views/admin/registered_sites/_index.html.erb b/app/views/admin/registered_sites/_index.html.erb index c91fef3..cd11b1b 100644 --- a/app/views/admin/registered_sites/_index.html.erb +++ b/app/views/admin/registered_sites/_index.html.erb @@ -10,19 +10,36 @@ <% @registeredsites.each do |site| %> - <%= site.site_domain %> + + <%= site.title.nil? ? site.site_domain : site.title %> +
+ +
+ <%= site.admin_email %> <% if !site.site_confirmed %> - <%= t("registered_sites.site_inactive") %>
+ <%= t("registered_sites.site_inactive") %>
<%= t("registered_sites.email_not_confirmed") %> <% elsif !site.access_granted %> - <%= t("registered_sites.site_inactive") %>
+ <%= t("registered_sites.site_inactive") %>
<%= t("registered_sites.site_permission_revoked") %> <% else %> - <%= t("registered_sites.site_active") %>
+ <%= t("registered_sites.site_active") %>
<% end %> + <%= site.category.nil? ? "Category not assigned" : "#{site.category.title}".html_safe %> + + <% site.tags.each do |tag| %> + + <%= tag.name %> + + <% end %> + <% if !site.site_confirmed %> Grant diff --git a/app/views/admin/registered_sites/edit.html.erb b/app/views/admin/registered_sites/edit.html.erb new file mode 100644 index 0000000..0577383 --- /dev/null +++ b/app/views/admin/registered_sites/edit.html.erb @@ -0,0 +1,6 @@ +<%= form_for @registered_site, url: admin_registered_site_path(@registered_site), html: {class: "form-horizontal main-forms previewable"} do |f| %> +
+
;">
+ <%= render :partial => 'form', locals: {f: f} %> +
+<% end %> \ No newline at end of file diff --git a/lib/registered_sites/engine.rb b/lib/registered_sites/engine.rb index bdbc4e3..97ef65a 100644 --- a/lib/registered_sites/engine.rb +++ b/lib/registered_sites/engine.rb @@ -5,6 +5,8 @@ module RegisteredSites module_label "registered_sites.registered_sites" base_url File.expand_path File.dirname(__FILE__) authorizable + taggable "RegisteredSite" + categorizable side_bar do head_label_i18n 'registered_sites.registered_sites', icon_class: "icons-earth" @@ -17,6 +19,14 @@ module RegisteredSites :priority=>1, :active_for_action=>{'admin/registered_sites'=>"index"}, :available_for => 'users' + + context_link 'categories', + :link_path=>"admin_module_app_categories_path" , + :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'registered_site').id}", + :priority=>2, + :active_for_action=>{'admin/registered_sites'=>'categories'}, + :active_for_category => 'RegisteredSite', + :available_for => 'managers' end end end