sibu 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c6f5a167c25ae09399fc380a29a3b28b5779b64
4
- data.tar.gz: 3d81f0ccfc1dcfc94187059384e84a043344a6ca
3
+ metadata.gz: 12b8c61886eced3159e2e597e31fe83c3bac36ca
4
+ data.tar.gz: f0a8a11c80f92c1a39a254aef356b26dbc9efe4e
5
5
  SHA512:
6
- metadata.gz: a7154da111bf85b4eb8062dfa7197c7f1eb1d2009ad92d5ed57925b530a5e4a868a529ec0a4e7b42eba5392102c44d5e7cf942131c17de21d0170545e3977c21
7
- data.tar.gz: 3c0d4ebba40926d6ea7e320b68acc32e44121e484e2671665d433dd2162a868ca98cf81803ee7b77eda70eb394b5b04391977060d1ab987b83e9c755e582a9e6
6
+ metadata.gz: 941e6278c17d84a88897be0a055c416e0c28fce3679d7a003cd55fcb055b53ac3a87e7f8d7ea9095b1f88d104c01fe3589c289d90f5ee471d2945083e1505e84
7
+ data.tar.gz: b9d7b3e5c8ecb60bedf2fb51c2d9eb4fc11ba05733e27a37528272269dbcf535b2f58a479e2ee50f9fb8d4c642bab96a5b64fcc70c580afc0af9af342c8a8149
@@ -79,14 +79,14 @@ function initQuillEditor(container) {
79
79
  return quill;
80
80
  }
81
81
 
82
-
83
82
  function initCropper(imgId) {
84
83
  var wrapper = $(".sibu_crop").first();
85
84
  var srcImg = $("#content_panel").find(".sb-editing img[data-id='" + imgId + "']").first();
86
85
  var srcContainer = srcImg.parent();
87
86
  var ratio = parseFloat(srcContainer.css("width")) / parseFloat(wrapper.css("width"));
88
- wrapper.css("height", (parseFloat(srcContainer.css("height")) / ratio) + "px");
89
- var cropper = new Cropper(wrapper.find("img")[0], {
87
+ var wrapperHeight = Math.min(320, parseFloat(srcContainer.css("height")) / ratio) + "px";
88
+ wrapper.css("height", wrapperHeight);
89
+ return new Cropper(wrapper.find("img")[0], {
90
90
  crop: function(event) {
91
91
  var data = event.detail;
92
92
  var cropper = this.cropper;
@@ -97,7 +97,8 @@ function initCropper(imgId) {
97
97
  var height = imageData.naturalHeight / imageScaledRatio + 'px';
98
98
  var marginLeft = -data.x / imageScaledRatio + 'px';
99
99
  var marginTop = -data.y / imageScaledRatio + 'px';
100
-
100
+ // console.log("crop detail : " + JSON.stringify(data));
101
+ // console.log('img data : ' + JSON.stringify(imageData));
101
102
  $("#element_style").val("width: " + width + "; height: " + height + "; margin-left: " + marginLeft + "; margin-top: " + marginTop +"; max-width: none; max-height: none;");
102
103
  }
103
104
  });
@@ -0,0 +1,35 @@
1
+ require_dependency "sibu/application_controller"
2
+
3
+ module Sibu
4
+ class DocumentsController < ApplicationController
5
+ def index
6
+ @documents = Sibu::Document.for_user(sibu_user)
7
+ end
8
+
9
+ def new
10
+ @document = Sibu::Document.new(user_id: send(Rails.application.config.sibu[:current_user]).id)
11
+ end
12
+
13
+ def create
14
+ @document = Sibu::Document.new(document_params)
15
+ if @document.save
16
+ redirect_to documents_url, notice: "Le document a bien été téléchargé."
17
+ else
18
+ flash.now[:alert] = "Une erreur s'est produite lors du téléchargement du document."
19
+ render :new
20
+ end
21
+ end
22
+
23
+ def destroy
24
+ @document = @document.find(params[:id])
25
+ @document.destroy
26
+ redirect_to documents_url, notice: "Le document a bien été supprimé."
27
+ end
28
+
29
+ private
30
+
31
+ def document_params
32
+ params.require(:document).permit!
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ module Sibu
2
+ module DocumentsHelper
3
+ end
4
+ end
@@ -16,11 +16,21 @@ module Sibu
16
16
  end
17
17
 
18
18
  def available_links
19
- options_from_collection_for_select(@site.pages, :id, :name, @element["value"])
19
+ options_from_collection_for_select(@site.pages.order(:name), :id, :name, @element["value"])
20
20
  end
21
21
 
22
- def is_internal(val)
23
- val.blank? || val == '#' || /^\d{1,3}$/.match(val.to_s)
22
+ def available_docs
23
+ options_from_collection_for_select(Sibu::Document.for_user(sibu_user), :file_url, :file_name, @element["value"])
24
+ end
25
+
26
+ def link_type(val)
27
+ if val.blank? || val == '#' || /^\d{1,3}$/.match(val.to_s)
28
+ 'internal'
29
+ elsif Sibu::Document.for_user(sibu_user).map {|d| d.file_url}.include?(val)
30
+ 'document'
31
+ else
32
+ 'external'
33
+ end
24
34
  end
25
35
 
26
36
  [:h1, :h2, :h3, :h4, :h5, :h6, :span].each do |t|
@@ -127,7 +137,7 @@ module Sibu
127
137
  val = content.delete("value") || ""
128
138
  text = content.delete("text");
129
139
  html_opts.merge!({data: {id: elt_id(elt), type: "link", repeat: repeat, children: children}}) if action_name != 'show'
130
- if val.to_s.include?('http')
140
+ if val.to_s.include?('/')
131
141
  content["href"] = val
132
142
  else
133
143
  content["href"] = @links.keys.include?(val.to_s) ? (action_name == 'show' ? link_path(val) : site_page_edit_content_path(@site.id, val)) : '#'
@@ -0,0 +1,8 @@
1
+ class Sibu::DocumentUploader < Shrine
2
+ plugin :validation_helpers
3
+
4
+ Attacher.validate do
5
+ validate_max_size 10*1024*1024, message: "est trop volumineux (10Mo maximum)"
6
+ # validate_mime_type_inclusion %w[application/pdf]
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ module Sibu
2
+ class Document < ApplicationRecord
3
+ include DocumentUploader::Attachment.new(:file, cache: :documents_cache, store: :documents_store)
4
+ extend Sibu::UserConcern
5
+
6
+ validates_presence_of :file_data
7
+
8
+ store :file_data, accessors: [:metadata], coder: JSON
9
+
10
+ def file_name
11
+ metadata[:filename]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ <%= form_for(@document) do |f| %>
2
+ <div class="sibu_field">
3
+ <%= f.label :file, "Sélection du document" %>
4
+ <div>
5
+ <%= f.hidden_field :file, value: @document.cached_file_data %>
6
+ <%= f.file_field :file %>
7
+ <small>Sélectionnez un document à télécharger depuis votre ordinateur</small>
8
+ </div>
9
+ </div>
10
+ <%= f.hidden_field :user_id %>
11
+ <div class="sibu_actions">
12
+ <%= f.submit 'Valider', data: {disable_with: "Téléchargement du document en cours..."} %>
13
+ <%= link_to 'Annuler', :back %>
14
+ </div>
15
+ <% end %>
@@ -0,0 +1,37 @@
1
+ <div class="sibu_view">
2
+ <div class="actions">
3
+ <%= link_to 'Télécharger un document', new_document_path %> <%= link_to 'Retour', :back %>
4
+ </div>
5
+ <h2>Documents téléchargés</h2>
6
+ <table class="sibu_documents">
7
+ <thead>
8
+ <tr>
9
+ <th>Nom</th>
10
+ <th>Taille</th>
11
+ <th>Mise à jour</th>
12
+ <th>Chemin d'accès (URL)</th>
13
+ <th></th>
14
+ </tr>
15
+ </thead>
16
+ <tbody>
17
+ <% @documents.each do |doc| %>
18
+ <tr>
19
+ <td><%= doc.metadata[:filename] %></td>
20
+ <td><%= doc.metadata[:size] > (1024 * 1024) ? "#{doc.metadata[:size] / (1024 * 1024)} Mo" : "#{doc.metadata[:size] / 1024} Ko" %></td>
21
+ <td><%= l doc.updated_at %></td>
22
+ <td><%= doc.file_url %></td>
23
+ <td>
24
+ <%= link_to 'Voir', doc.file_url, target: '_blank' %> |
25
+ <%= link_to 'Supprimer', document_path(doc), method: :delete, data: {confirm: "Supprimer le document \"#{doc.metadata[:filename]}\" ?"} %>
26
+ </td>
27
+ </tr>
28
+ <% end %>
29
+ <% if @documents.empty? %>
30
+ <tr>
31
+ <td colspan="4">Aucun document téléchargé pour le moment.</td>
32
+ </tr>
33
+ <% end %>
34
+ </tbody>
35
+ </table>
36
+ </div>
37
+
@@ -0,0 +1,13 @@
1
+ <div class="sibu_view">
2
+ <div class="actions">
3
+ <%= link_to 'Retour', :back %>
4
+ </div>
5
+ <h2>Télécharger un document</h2>
6
+ <p>
7
+ Vous pouvez télécharger tous types de documents d'une taille inférieure à 10Mo.
8
+ Pour les documents textes, favorisez le format PDF pour une compatibilité optimale.
9
+ </p>
10
+ <div class="sibu_form">
11
+ <%= render 'form' %>
12
+ </div>
13
+ </div>
@@ -1,4 +1,4 @@
1
- <div id="pages" class="sibu_view">
1
+ <div class="sibu_view">
2
2
  <div class="actions">
3
3
  <%= link_to 'Télécharger une image', new_image_path %> <%= link_to 'Retour', :back %>
4
4
  </div>
@@ -3,23 +3,28 @@
3
3
  <%= render 'element_actions' %>
4
4
  <div class="sibu_edit_form">
5
5
  <%= form_tag(update_element_site_page_path(@site.id, @page.id), method: :patch, remote: true) do |f| %>
6
- <% internal = is_internal(@element["value"]) %>
6
+ <% current_type = link_type(@element["value"]) %>
7
7
  <div class="sibu_field">
8
8
  <%= label_tag 'element[text]', 'Libellé' %>
9
9
  <%= text_field_tag 'element[text]', @element["text"] %>
10
10
  </div>
11
11
  <div id="link_internal" class="sibu_field">
12
- <%= radio_button_tag :mode, 'internal', internal, class: 'radio' %>
12
+ <%= radio_button_tag :mode, 'internal', current_type == 'internal', class: 'radio' %>
13
13
  <%= label_tag 'mode_internal', 'Lien vers une page du site' %>
14
- <%= select_tag 'element[value]', options_from_collection_for_select(@site.pages.order(:name), :id, :name, @element["value"]),
15
- prompt: 'Sélectionnez une page', disabled: !internal %>
16
- <%= hidden_field_tag 'element[target]', '_self', disabled: !internal %>
14
+ <%= select_tag 'element[value]', available_links, prompt: 'Sélectionnez une page', disabled: current_type != 'internal' %>
15
+ <%= hidden_field_tag 'element[target]', '_self', disabled: current_type != 'internal' %>
17
16
  </div>
18
17
  <div id="link_external" class="sibu_field">
19
- <%= radio_button_tag :mode, 'external', !internal, class: 'radio' %>
18
+ <%= radio_button_tag :mode, 'external', current_type == 'external', class: 'radio' %>
20
19
  <%= label_tag 'mode_external', 'Lien vers un autre site' %>
21
- <%= text_field_tag 'element[value]', (@element["value"] unless internal), placeholder: 'Ex : http://www.un-site.com', disabled: internal %>
22
- <%= hidden_field_tag 'element[target]', '_blank', disabled: internal %>
20
+ <%= text_field_tag 'element[value]', (@element["value"] if current_type == 'external'), placeholder: 'Ex : http://www.un-site.com', disabled: current_type != 'external' %>
21
+ <%= hidden_field_tag 'element[target]', '_blank', disabled: current_type != 'external' %>
22
+ </div>
23
+ <div id="link_document" class="sibu_field">
24
+ <%= radio_button_tag :mode, 'document', current_type == 'document', class: 'radio' %>
25
+ <%= label_tag 'mode_document', 'Lien vers un document' %>
26
+ <%= select_tag 'element[value]', available_docs, prompt: 'Sélectionnez un document', disabled: current_type != 'document' %>
27
+ <%= hidden_field_tag 'element[target]', '_blank', disabled: current_type != 'document' %>
23
28
  </div>
24
29
  <%= hidden_field_tag 'element[id]', @element["id"] %>
25
30
  <%= hidden_field_tag :element_id, @element_id %>
@@ -19,10 +19,14 @@
19
19
  <% if @element["src"] == DEFAULT_IMG || @element["src"].blank? %>
20
20
  <p>Veuillez sélectionner une image.</p>
21
21
  <% end %>
22
+ <div class="sibu_is_cropped" style="display: <%= (@element["src"] == DEFAULT_IMG || @element["src"].blank?) ? 'none' : 'block' %>">
23
+ <%= check_box_tag('is_cropped', true, !@element["style"].blank?, id: 'is_cropped', class: 'checkbox') %>
24
+ <%= label_tag 'is_cropped', "Recadrer l'image" %>
25
+ </div>
22
26
  <div class="sibu_crop">
23
27
  <%= image_tag(@element["src"]) unless @element["src"] == DEFAULT_IMG || @element["src"].blank? %>
24
28
  </div>
25
- <div class="sibu_field">
29
+ <div class="sibu_field" style="display: <%= (@element["src"] == DEFAULT_IMG || @element["src"].blank?) ? 'none' : 'block' %>">
26
30
  <%= label_tag 'element[alt]', 'Légende / texte alternatif' %>
27
31
  <%= text_field_tag 'element[alt]', @element["alt"] %>
28
32
  </div>
@@ -37,6 +37,7 @@ editPanel.slideDown("fast", function() {
37
37
  });
38
38
  <% when 'media' %>
39
39
  var images = editPanel.find(".sibu_image img");
40
+ var isCropped = $("#is_cropped"), cropper;
40
41
  images.click(function() {
41
42
  if(!$(this).hasClass('selected')) {
42
43
  images.removeClass('selected');
@@ -45,12 +46,29 @@ editPanel.slideDown("fast", function() {
45
46
  $("#element_alt").val($(this).data("alt"));
46
47
  editPanel.find(".sibu_crop").html('<img src="' + $("#element_src").val() + '"/>');
47
48
  editPanel.find(".sibu_selected_image > p:first-child").hide();
48
- initCropper("<%= @element_id %>");
49
+ editPanel.find(".sibu_selected_image").find(".sibu_is_cropped").show();
50
+ editPanel.find(".sibu_selected_image").find(".sibu_field").show();
51
+ if(isCropped.is(":checked")) {
52
+ cropper = initCropper("<%= @element_id %>");
53
+ }
49
54
  }
50
55
  });
51
56
  if(editPanel.find(".sibu_crop img").size() > 0) {
52
- initCropper("<%= @element_id %>");
57
+ if(isCropped.is(":checked")) {
58
+ cropper = initCropper("<%= @element_id %>");
59
+ }
53
60
  }
61
+ isCropped.change(function() {
62
+ if($(this).is(":checked")) {
63
+ cropper = initCropper("<%= @element_id %>");
64
+ } else {
65
+ $("#element_style").val("");
66
+ $(".sibu_crop").attr("style", "");
67
+ if(cropper) {
68
+ cropper.destroy();
69
+ }
70
+ }
71
+ });
54
72
  <% when 'link' %>
55
73
  $("input[name='mode']").change(function() {
56
74
  var selected = $(this).val();
@@ -1,6 +1,7 @@
1
1
  <div class="sibu_view">
2
2
  <div class="actions">
3
3
  <%= link_to "Bibliothèque d'images", images_path %>
4
+ <%= link_to "Documents", documents_path %>
4
5
  <%= link_to 'Créer un site', new_site_path %>
5
6
  </div>
6
7
  <h2>Liste des sites</h2>
@@ -5,7 +5,9 @@ Shrine.storages = {
5
5
  cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"),
6
6
  store: Shrine::Storage::FileSystem.new("public", prefix: "uploads/store"),
7
7
  styles_cache: Shrine::Storage::FileSystem.new("public", prefix: "stylesheets/cache"),
8
- styles_store: Shrine::Storage::FileSystem.new("public", prefix: "stylesheets/store")
8
+ styles_store: Shrine::Storage::FileSystem.new("public", prefix: "stylesheets/store"),
9
+ documents_cache: Shrine::Storage::FileSystem.new("public", prefix: "documents/cache"),
10
+ documents_store: Shrine::Storage::FileSystem.new("public", prefix: "documents/store")
9
11
  }
10
12
 
11
13
  Shrine.plugin :activerecord
data/config/routes.rb CHANGED
@@ -20,7 +20,6 @@ Sibu::Engine.routes.draw do
20
20
  delete 'delete_section', on: :member
21
21
  end
22
22
  end
23
-
24
- resources :images
23
+ resources :images, :documents
25
24
  end
26
25
  end
@@ -1,7 +1,7 @@
1
1
  class MoveImagesToUserLevel < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  add_column :sibu_images, :user_id, :integer
4
- Sibu::Image.where("site_id IS NOT NULL").each {|img| img.update(user_id: img.site.user_id)}
4
+ Sibu::Image.where("site_id IS NOT NULL").each {|img| img.update(user_id: Sibu::Site.find(img.site_id).user_id)}
5
5
  remove_column :sibu_images, :site_id
6
6
  end
7
7
  end
@@ -0,0 +1,10 @@
1
+ class CreateSibuDocuments < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :sibu_documents do |t|
4
+ t.integer :user_id
5
+ t.text :file_data
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
data/lib/sibu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sibu
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Baptiste Vilain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-23 00:00:00.000000000 Z
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -134,20 +134,24 @@ files:
134
134
  - app/assets/stylesheets/sibu/icons.scss
135
135
  - app/assets/stylesheets/sibu/sibu.css
136
136
  - app/controllers/sibu/application_controller.rb
137
+ - app/controllers/sibu/documents_controller.rb
137
138
  - app/controllers/sibu/images_controller.rb
138
139
  - app/controllers/sibu/pages_controller.rb
139
140
  - app/controllers/sibu/sites_controller.rb
140
141
  - app/helpers/sibu/application_helper.rb
142
+ - app/helpers/sibu/documents_helper.rb
141
143
  - app/helpers/sibu/images_helper.rb
142
144
  - app/helpers/sibu/pages_helper.rb
143
145
  - app/helpers/sibu/sites_helper.rb
144
146
  - app/jobs/sibu/application_job.rb
145
147
  - app/mailers/sibu/application_mailer.rb
148
+ - app/models/concerns/sibu/document_uploader.rb
146
149
  - app/models/concerns/sibu/image_uploader.rb
147
150
  - app/models/concerns/sibu/sections_concern.rb
148
151
  - app/models/concerns/sibu/style_uploader.rb
149
152
  - app/models/concerns/sibu/user_concern.rb
150
153
  - app/models/sibu/application_record.rb
154
+ - app/models/sibu/document.rb
151
155
  - app/models/sibu/dynamic_style.rb
152
156
  - app/models/sibu/image.rb
153
157
  - app/models/sibu/page.rb
@@ -156,6 +160,9 @@ files:
156
160
  - app/views/layouts/sibu/application.html.erb
157
161
  - app/views/layouts/sibu/edit_content.html.erb
158
162
  - app/views/layouts/sibu/site.html.erb
163
+ - app/views/sibu/documents/_form.html.erb
164
+ - app/views/sibu/documents/index.html.erb
165
+ - app/views/sibu/documents/new.html.erb
159
166
  - app/views/sibu/images/_edit_form.html.erb
160
167
  - app/views/sibu/images/_form.html.erb
161
168
  - app/views/sibu/images/edit.js.erb
@@ -215,6 +222,7 @@ files:
215
222
  - db/migrate/20180301152101_add_default_styles_to_templates.rb
216
223
  - db/migrate/20180321144021_move_images_to_user_level.rb
217
224
  - db/migrate/20180321170310_add_version_to_sibu_sites.rb
225
+ - db/migrate/20180405095448_create_sibu_documents.rb
218
226
  - lib/sibu.rb
219
227
  - lib/sibu/engine.rb
220
228
  - lib/sibu/utils.rb