diff --git a/app/controllers/admin/faqs_controller.rb b/app/controllers/admin/faqs_controller.rb new file mode 100644 index 0000000..9854b72 --- /dev/null +++ b/app/controllers/admin/faqs_controller.rb @@ -0,0 +1,63 @@ +class Admin::FaqsController < Admin::BaseController + before_action :fetch_faq, only: [:show, :edit, :update, :destroy] + + # GET /admin/faqs + def index + @faqs = Faq.all + end + + # GET /admin/faqs/:id + def show; end + + # GET /admin/faqs/new + def new + @faq = Faq.new + end + + # GET /admin/faqs/:id/edit + def edit; end + + # POST /admin/faqs + def create + @faq = Faq.new(fetch_params) + if @faq.save + flash[:success] = 'FAQ created successfuly' + redirect_to admin_faqs_path + else + flash[:error] = 'FAQ not created' + render :new + end + end + + # PUT/PATCH /admin/faqs/:id/update + def update + if @faq.update_attributes(fetch_params) + flash[:success] = 'FAQ updated successfuly' + redirect_to admin_faq_path(@faq) + else + flash[:error] = 'FAQ not updated' + render :edit + end + end + + # DELETE /admin/faqs/:id/destroy + def destroy + if @faq.destroy + flash[:success] = 'FAQ destroyed' + else + flash[:error] = 'FAQ not destroyed' + end + + redirect_to admin_faqs_path + end + + private + + def fetch_faq + @faq = Faq.find(params[:id]) + end + + def fetch_params + params.require(:faq).permit(:title, :body) + end +end diff --git a/app/views/admin/faqs/_faq.html.erb b/app/views/admin/faqs/_faq.html.erb new file mode 100644 index 0000000..4f4b081 --- /dev/null +++ b/app/views/admin/faqs/_faq.html.erb @@ -0,0 +1,20 @@ + + <%= link_to "##{faq.id}", admin_faq_path(faq) %> + <%= faq.priority %> + <%= link_to faq.title, admin_faq_path(faq) %> + <%= faq.body %> + <%= I18n.l(faq.created_at, format: :short) %> + <%= I18n.l(faq.updated_at, format: :short) rescue '-' %> + + <%= link_to admin_faq_path(faq) do %> + + <% end %> + <%= link_to edit_admin_faq_path(faq) do %> + + <% end %> + <%= link_to admin_faq_path(faq), method: :delete, + data: { confirm: 'The FAQ entry is going to be destroyed' } do %> + + <% end %> + + diff --git a/app/views/admin/faqs/_form.html.erb b/app/views/admin/faqs/_form.html.erb new file mode 100644 index 0000000..cb78c2c --- /dev/null +++ b/app/views/admin/faqs/_form.html.erb @@ -0,0 +1,16 @@ +<%= bootstrap_form_for([:admin, @faq], layout: :horizontal, label_col: 'col-xs-3', + control_col: 'col-xs-8') do |f| %> + <%= f.text_field :title, required: true %> + <%= f.number_field :priority %> + <%= f.text_area :body, cols: 20, rows: 10, required: true %> + + +
+
+ <%= link_to 'Cancel', admin_faqs_path, class: 'btn btn-default' %> +
+
+ <%= f.submit class: 'btn btn-success' %> +
+
+<% end %> diff --git a/app/views/admin/faqs/edit.html.erb b/app/views/admin/faqs/edit.html.erb new file mode 100644 index 0000000..84fc9b0 --- /dev/null +++ b/app/views/admin/faqs/edit.html.erb @@ -0,0 +1,11 @@ +
+
+
+
+

Edit FAQ

+
+
+ <%= render partial: 'form' %> +
+
+
diff --git a/app/views/admin/faqs/index.html.erb b/app/views/admin/faqs/index.html.erb new file mode 100644 index 0000000..121ce09 --- /dev/null +++ b/app/views/admin/faqs/index.html.erb @@ -0,0 +1,33 @@ +
+ <%= link_to new_admin_faq_path, class: "btn btn-default", role: "button" do %> + + New FAQ + <% end %> +
+ +

FAQ

+
+ +
+
+
+ + + + + + + + + + + + + + + <%= render partial: 'faq', collection: @faqs %> + +
IdPriorityTitleBodyCreated atUpdated atActions
+
+
+
diff --git a/app/views/admin/faqs/new.html.erb b/app/views/admin/faqs/new.html.erb new file mode 100644 index 0000000..50735e2 --- /dev/null +++ b/app/views/admin/faqs/new.html.erb @@ -0,0 +1,11 @@ +
+
+
+
+

New FAQ entry

+
+
+ <%= render partial: 'form' %> +
+
+
diff --git a/app/views/admin/faqs/show.html.erb b/app/views/admin/faqs/show.html.erb new file mode 100644 index 0000000..fcc6474 --- /dev/null +++ b/app/views/admin/faqs/show.html.erb @@ -0,0 +1,26 @@ +
+
+
+

<%= @faq.title %>

+
+ +
+ +

+ <%= @faq.body %> +

+
+ + <%= link_to 'Back to FAQ', admin_faqs_path %> + + <%= link_to edit_admin_faq_path(@faq), class: 'btn btn-default' do %> + + Edit + <% end %> + + <%= link_to admin_faq_path(@faq), method: :delete, + data: { confirm: 'FAQ entry will be deleted' }, class: 'btn btn-default right' do %> + + Delete + <% end %> +
diff --git a/app/views/shared/_admin.html.erb b/app/views/shared/_admin.html.erb index 7ed7b91..0ff754f 100644 --- a/app/views/shared/_admin.html.erb +++ b/app/views/shared/_admin.html.erb @@ -1,39 +1,42 @@ diff --git a/config/routes.rb b/config/routes.rb index d8ececa..6c4f625 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,103 +1,105 @@ Rails.application.routes.draw do root 'application#index' post 'grnet' => 'application#grnet' get 'institutional' => 'application#institutional' match 'vima', to: 'application#vima', :via => [:get, :post] get 'logout' => 'application#logout' resources :clients, only: [:index, :show] do member do get :jobs get :logs get :stats post :stats get :users get :restore post :run_restore post :restore_selected delete :remove_user end collection do post :index end end resources :clients, only: [], param: :client_id do member do get :tree end end resources :invitations, only: [:create] get '/invitations/:host_id/:verification_code/accept' => 'invitations#accept', as: :accept_invitation resources :hosts, only: [:new, :create, :show, :edit, :update, :destroy] do member do post :submit_config post :disable delete :revoke end collection do get :fetch_vima_hosts, to: 'hosts#fetch_vima_hosts', as: :fetch_vima end resources :jobs, only: [:new, :create, :show, :edit, :update, :destroy] do member do patch :toggle_enable post :backup_now end end resources :filesets, only: [:show, :new, :create, :edit, :update, :destroy] resources :schedules, only: [:show, :new, :edit, :create, :update, :destroy] end namespace :admin do match '/', to: 'base#index', via: [:get, :post] get '/login' => 'base#login', as: :login resources :settings, only: [:index, :new, :create, :edit, :update] do member do delete :reset end end resources :clients, only: [:index, :show] do member do get :jobs get :logs get :stats post :stats get :configuration post :disable post :block post :unblock delete :revoke end end resources :hosts, only: [] do collection do get :unverified end member do post :verify end end resources :users, only: [:index, :new, :create, :show, :edit, :update] do member do patch :ban patch :unban end end resources :pools, only: [:index, :new, :create] + + resources :faqs end end diff --git a/spec/routing/admin/faq_routing_spec.rb b/spec/routing/admin/faq_routing_spec.rb new file mode 100644 index 0000000..5e7a2dd --- /dev/null +++ b/spec/routing/admin/faq_routing_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe Admin::FaqsController do + it 'routes GET /admin/faqs' do + expect(get('/admin/faqs')).to route_to(controller: 'admin/faqs', action: 'index') + end + + it 'routes GET /admin/faqs/new' do + expect(get('/admin/faqs/new')). + to route_to(controller: 'admin/faqs', action: 'new') + end + + it 'routes GET /admin/faqs/1' do + expect(get('/admin/faqs/1')). + to route_to(controller: 'admin/faqs', action: 'show', id: '1') + end + + it 'routes GET /admin/faqs/1/edit' do + expect(get('/admin/faqs/1/edit')). + to route_to(controller: 'admin/faqs', action: 'edit', id: '1') + end + + it 'routes PUT /admin/faqs/1' do + expect(put('/admin/faqs/1')). + to route_to(controller: 'admin/faqs', action: 'update', id: '1') + end + + it 'routes POST /admin/faqs' do + expect(post('/admin/faqs')). + to route_to(controller: 'admin/faqs', action: 'create') + end + + it 'routes DELETE /admin/faqs/1' do + expect(delete('/admin/faqs/1')). + to route_to(controller: 'admin/faqs', action: 'destroy', id: '1') + end +end