diff --git a/Gemfile b/Gemfile index d1b9cae281ff09f01f04851583b66bad3e3b6274..ca2585d7100fe0e060eab437b9724129b15e45c0 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,7 @@ gem 'has_scope', '~> 0.8.0' # Front gem 'jquery-rails' +gem 'angularjs-rails' gem 'sassc-rails' gem 'jbuilder' gem 'kamifusen'#, path: '../kamifusen' diff --git a/Gemfile.lock b/Gemfile.lock index 8575dc8d6e97bf3358f216c4e54eeb3bddabb432..6351eebe9b1cb9dd038c5b9b6402272e8c550b8a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,6 +80,7 @@ GEM zeitwerk (~> 2.3) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) + angularjs-rails (1.8.0) annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) @@ -426,6 +427,7 @@ PLATFORMS ruby DEPENDENCIES + angularjs-rails annotate aws-sdk-s3 bootsnap (>= 1.4.4) diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js index 8325a2d7fb557ccbcf2813bec4b23fe348317df0..b350adb49443f63a448c825187b550e258957dd1 100644 --- a/app/assets/javascripts/admin.js +++ b/app/assets/javascripts/admin.js @@ -5,6 +5,7 @@ //= require notyf/notyf.min //= require simple_form_password_with_hints //= require simple_form_bs5_file_input +//= require angular //= require cropperjs/dist/cropper //= require jquery-cropper/dist/jquery-cropper //= require appstack/app diff --git a/app/controllers/admin/communication/website/blocks_controller.rb b/app/controllers/admin/communication/website/blocks_controller.rb index 4b0abb3b4b35d6f45e74cd097e5618ed0873af05..888a6611efe19f419b22f1499af2b28055f78edb 100644 --- a/app/controllers/admin/communication/website/blocks_controller.rb +++ b/app/controllers/admin/communication/website/blocks_controller.rb @@ -10,6 +10,10 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We end end + def show + breadcrumb + end + def new @block.about_type = params[:about_type] @block.about_id = params[:about_id] @@ -50,7 +54,11 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We super add_breadcrumb @block.about.model_name.human(count: 2), [:admin, @block.about.class] add_breadcrumb @block.about, [:admin, @block.about] - add_breadcrumb t('communication.website.block.choose_template') + if @block.new_record? + add_breadcrumb t('communication.website.block.choose_template') + else + add_breadcrumb @block + end end diff --git a/app/models/communication/website/block.rb b/app/models/communication/website/block.rb index ca0170661f68027e26a90afd92a2439684c10567..db79b935c6be4b05d779c3533070232dcaa65383 100644 --- a/app/models/communication/website/block.rb +++ b/app/models/communication/website/block.rb @@ -36,6 +36,11 @@ class Communication::Website::Block < ApplicationRecord partners: 200 } + def data=(value) + value = JSON.parse value if value.is_a? String + super(value) + end + def to_s "Bloc #{position}" end diff --git a/app/views/admin/communication/website/blocks/_list.html.erb b/app/views/admin/communication/website/blocks/_list.html.erb index 462075f63346224998ba3da7ebbfb3195d3a7747..e215b67157d89447740fae3b0cab2d657bb63439 100644 --- a/app/views/admin/communication/website/blocks/_list.html.erb +++ b/app/views/admin/communication/website/blocks/_list.html.erb @@ -15,14 +15,19 @@ <th width="20" class="ps-0"> </th> <th><%= Communication::Website::Block.human_attribute_name('name') %></th> <th><%= Communication::Website::Block.human_attribute_name('template') %></th> + <th></th> </tr> </thead> <tbody data-sortable data-sort-url="<%= reorder_admin_communication_website_blocks_path %>"> <% about.blocks.ordered.each do |block| %> <tr data-id="<%= block.id %>"> <td><i class="fa fa-bars handle"></i></td> - <td><%= link_to block, edit_admin_communication_website_block_path(block) %></td> + <td><%= link_to block, admin_communication_website_block_path(block) %></td> <td><%= block.template_i18n %></td> + <td class="text-end"> + <%= edit_link block %> + <%= destroy_link block %> + </td> </tr> <% end %> </tbody> diff --git a/app/views/admin/communication/website/blocks/_static.html.erb b/app/views/admin/communication/website/blocks/_static.html.erb index 48cbe043658cf81c9efdc34076c301ccbc8bbccd..2b5dbed63c6d3d0f53312df54e68bcdd3fdcccb4 100644 --- a/app/views/admin/communication/website/blocks/_static.html.erb +++ b/app/views/admin/communication/website/blocks/_static.html.erb @@ -3,5 +3,5 @@ blocks: <% about.blocks.each do |block| %> - template: <%= block.template %> data: -<%= render "admin/communication/website/blocks/templates/#{block.template}/static", block: block %><% end %> +<%= render "admin/communication/website/blocks/templates/#{block.template}/static", block: block if block.data %><% end %> <% end %> diff --git a/app/views/admin/communication/website/blocks/edit.html.erb b/app/views/admin/communication/website/blocks/edit.html.erb index 7502b581b79a56009d16a1c8c221b9beb2df9cc8..0760375b3d46559d43d8c85ab571233b749d9500 100644 --- a/app/views/admin/communication/website/blocks/edit.html.erb +++ b/app/views/admin/communication/website/blocks/edit.html.erb @@ -1,8 +1,14 @@ <% content_for :title, @block %> - -<%= simple_form_for [:admin, @block] do |f| %> - <%= render "admin/communication/website/blocks/templates/#{@block.template}/edit", f: f %> - <% content_for :action_bar_right do %> - <%= submit f %> +<% +@block.data = {} if @block.data.nil? || @block.data.blank? +@block.data['elements'] ||= [] +%> +<div ng-app ng-init="data = <%= @block.data.is_a?(String) ? @block.data : @block.data.to_json %>"> + <%= simple_form_for [:admin, @block] do |f| %> + <%= render "admin/communication/website/blocks/templates/#{@block.template}/edit", f: f %> + <textarea name="communication_website_block[data]" rows="20" cols="200" class="d-none">{{ data | json}}</textarea> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> <% end %> -<% end %> +</div> diff --git a/app/views/admin/communication/website/blocks/show.html.erb b/app/views/admin/communication/website/blocks/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..abb88f0df4d096f307b3890a81dfbbc466b084ba --- /dev/null +++ b/app/views/admin/communication/website/blocks/show.html.erb @@ -0,0 +1,7 @@ +<% content_for :title, @block %> + +<%= render "admin/communication/website/blocks/templates/#{@block.template}/show" %> + +<% content_for :action_bar_right do %> + <%= edit_link @block %> +<% end %> diff --git a/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb b/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb index f805d4a4e69b8e04508372115e218b5d2d98d1e1..0c6c5f5815f8de8a585ddd28f2ff1838ba503a05 100644 --- a/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb +++ b/app/views/admin/communication/website/blocks/templates/organization_chart/_edit.html.erb @@ -1 +1,41 @@ -<%= f.input :data %> +<a class="<%= button_classes('mb-2') %>" ng-click="data.elements.push({title: 'Role name', persons: []})">Add role</a> +<div class="card" ng-repeat="element in data.elements"> + <div class="card-body"> + <div class="row"> + <div class="col-md-5"> + <div class="row"> + <div class="col-md-11"> + <input class="form-control" type="text" ng-model="element.title"> + </div> + <div class="col-md-1 text-end"> + <a class="btn btn-sm btn-danger mt-1" ng-click="data.elements.splice(data.elements.indexOf(element))"><i class="fas fa-trash"></i></a> + </div> + </div> + </div> + <div class="offset-md-1 col-md-6"> + <div class="row"> + <div class="col-md-8"> + <p>People</p> + </div> + <div class="col-md-4 text-end"> + <a class="<%= button_classes %>" ng-click="element.persons.push({slug: ''})">Add person</a> + </div> + </div> + <div ng-repeat="person in element.persons" class="mb-2"> + <div class="row"> + <div class="col-md-11"> + <select class="form-select select" ng-model="person.slug"> + <% @website.university.people.each_with_index do |person, index| %> + <option value="<%= person.slug %>"><%= person %></option> + <% end %> + </select> + </div> + <div class="col-md-1 text-end"> + <a class="btn btn-sm btn-danger mt-1" ng-click="element.persons.splice(element.persons.indexOf(person))"><i class="fas fa-trash"></i></a> + </div> + </div> + </div> + </div> + </div> + </div> +</div> diff --git a/app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb b/app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..e9da4c0eefb2d5a690f829353d7866e6a390699d 100644 --- a/app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb +++ b/app/views/admin/communication/website/blocks/templates/organization_chart/_show.html.erb @@ -0,0 +1,6 @@ +<% @block.data['elements'].each do |element| %> + <h2><%= element['title'] %></h2> + <% element['persons'].each do |person| %> + <p><%= person['slug'] %></p> + <% end %> +<% end %> diff --git a/app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb b/app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb index 1d3d08e8428a44685698a4bec507e915b6e5c8bc..8442a6bb1c0845b8982428a824ee66851eb7b133 100644 --- a/app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb +++ b/app/views/admin/communication/website/blocks/templates/organization_chart/_static.html.erb @@ -1,4 +1,10 @@ - - title: Leadership +<% if !block.data.nil? && !block.data.is_a?(String) && block.data.has_key?('elements') %> +<% block.data['elements'].each do |element| %> + - title: > + <%= element['title'] %> persons: - - amah-edoh - - liliane-umubyeyi +<% element['persons'].each do |person| %> + - "<%= person['slug'] %>" +<% end %> +<% end %> +<% end %> diff --git a/app/views/admin/communication/website/blocks/templates/partners/_edit.html.erb b/app/views/admin/communication/website/blocks/templates/partners/_edit.html.erb index f805d4a4e69b8e04508372115e218b5d2d98d1e1..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/app/views/admin/communication/website/blocks/templates/partners/_edit.html.erb +++ b/app/views/admin/communication/website/blocks/templates/partners/_edit.html.erb @@ -1 +0,0 @@ -<%= f.input :data %> diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 3cddac9b89f9094f7a8b3db27a72bc19b8ff8e56..76cd8c1fe124b9c3df986a6b4a767b0ad9cdaa5c 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -25,7 +25,7 @@ namespace :communication do resources :authors, controller: 'website/authors', only: [:index, :show] resources :posts, controller: 'website/posts' resources :curations, path: 'posts/curations', as: :post_curations, controller: 'website/posts/curations', only: [:new, :create] - resources :blocks, controller: 'website/blocks', except: [:index, :show] do + resources :blocks, controller: 'website/blocks', except: :index do collection do post :reorder end