five-two-nw-olivander 0.2.0.6 → 0.2.0.8

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
  SHA256:
3
- metadata.gz: ec1b83147e32bcad39702fd0a0a42a71a819e6f16ccc04ce2bf736a72cf8ba14
4
- data.tar.gz: 0fa90392ac13ae2161024e59def15f555c7f38e8ebf036bf4787bd0f91a72602
3
+ metadata.gz: d898798155655b25246bd5f3ed6db6527749b8626ccb877ad09ad49c4461cf16
4
+ data.tar.gz: e034cbc59cd38d51d5dd3d82cf628db6ba5ecb935af80fb118575f16a57d0b7d
5
5
  SHA512:
6
- metadata.gz: 93c448ec29561ffd681659106967a9149d17a877c123c737f05d98f408643e698fef4930f3cf0e310caa59acc675e0ae095c6dc9fc878d94c13ee0c46ebb3838
7
- data.tar.gz: 63b5b466d541df95458ed0f7474aab9da06dba1803fa5a6118b1882e12391414824bdba931d9931ed065ccabbfdeedad945fb368063f758727f9cb0aeedd7716
6
+ metadata.gz: 3d48968d12e4474b5800451cdfea383c2dd90c22d636887ab12c0d0147a1c6519a41267ab58d90a400986dda16043eea7596825dfc9ef389cac79819f4fc4d7e
7
+ data.tar.gz: 72e4e087d0bed9d5fed3c709ba15d37e411da184eb76d4e1ccba6443b678ff3980eb7fa71a13cd0624ca989b7ddf75d18e6fea1f415753942d8a3375c3f57b55
@@ -3,11 +3,23 @@ import { Controller } from "@hotwired/stimulus"
3
3
  // Connects to data-controller="input-control-association"
4
4
  export default class extends Controller {
5
5
  connect() {
6
+ console.log('setting up select2')
6
7
  var self = this,
7
8
  el = self.element;
9
+
10
+ console.log(el.dataset)
11
+
8
12
  if (!$(el).hasClass("select2-hidden-accessible")) {
9
13
  $(el).select2({
10
14
  dropdownParent: $(el).parent(),
15
+ tags: el.dataset.taggable == 'true',
16
+ createTag: function (tag) {
17
+ return {
18
+ id: tag.term,
19
+ text: tag.term,
20
+ isNew : true
21
+ };
22
+ },
11
23
  ajax: {
12
24
  url: el.dataset.collectionPath,
13
25
  delay: 250,
@@ -15,10 +27,40 @@ export default class extends Controller {
15
27
  dataType: 'json',
16
28
  processResults: function(data) {
17
29
  return { results: data.map(function(map) {
18
- return { id: map.id, text: map.text || map.name || map.description };
30
+ return {
31
+ id: map.id,
32
+ text: map.text || map.name || map.description,
33
+ children: map.children
34
+ };
19
35
  }) };
20
36
  }
21
37
  }
38
+ }).on('select2:select', function (e) {
39
+
40
+ let tag = e.params.data;
41
+ if (tag.isNew === true)
42
+ {
43
+ let csrfToken = document.querySelector("[name='csrf-token']").content,
44
+ data = new FormData()
45
+ data.append("authenticity_token", document.querySelector('meta[name="csrf-token"]').content)
46
+ data.append(el.dataset.tagFieldName, tag.text)
47
+ fetch(el.dataset.collectionPath, {
48
+ method: 'POST',
49
+ headers: {
50
+ "X-CSRF-Token": csrfToken,
51
+ Accept: "application/json"
52
+ },
53
+ body: data
54
+ })
55
+ .then(r => r.json())
56
+ .then(function(json) {
57
+ $(el).find(`option[value='${tag.id}']`).each(function(idx, opt) {
58
+ opt.value = json.id
59
+ })
60
+ $(el).select2().trigger('change')
61
+ return true
62
+ })
63
+ }
22
64
  })
23
65
  }
24
66
  }
@@ -0,0 +1,2 @@
1
+ const t="a[data-confirm], a[data-method], a[data-remote]:not([disabled]), a[data-disable-with], a[data-disable]";const e={selector:"button[data-remote]:not([form]), button[data-confirm]:not([form])",exclude:"form button"};const n="select[data-remote], input[data-remote], textarea[data-remote]";const o="form:not([data-turbo=true])";const a="form:not([data-turbo=true]) input[type=submit], form:not([data-turbo=true]) input[type=image], form:not([data-turbo=true]) button[type=submit], form:not([data-turbo=true]) button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])";const r="input[data-disable-with]:enabled, button[data-disable-with]:enabled, textarea[data-disable-with]:enabled, input[data-disable]:enabled, button[data-disable]:enabled, textarea[data-disable]:enabled";const c="input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, input[data-disable]:disabled, button[data-disable]:disabled, textarea[data-disable]:disabled";const s="input[name][type=file]:not([disabled])";const i="a[data-disable-with], a[data-disable]";const u="button[data-remote][data-disable-with], button[data-remote][data-disable]";let l=null;const loadCSPNonce=()=>{const t=document.querySelector("meta[name=csp-nonce]");return l=t&&t.content};const cspNonce=()=>l||loadCSPNonce();const d=Element.prototype.matches||Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector;const matches=function(t,e){return e.exclude?d.call(t,e.selector)&&!d.call(t,e.exclude):d.call(t,e)};const m="_ujsData";const getData=(t,e)=>t[m]?t[m][e]:void 0;const setData=function(t,e,n){t[m]||(t[m]={});return t[m][e]=n};const $=t=>Array.prototype.slice.call(document.querySelectorAll(t));const isContentEditable=function(t){var e=false;do{if(t.isContentEditable){e=true;break}t=t.parentElement}while(t);return e};const csrfToken=()=>{const t=document.querySelector("meta[name=csrf-token]");return t&&t.content};const csrfParam=()=>{const t=document.querySelector("meta[name=csrf-param]");return t&&t.content};const CSRFProtection=t=>{const e=csrfToken();if(e)return t.setRequestHeader("X-CSRF-Token",e)};const refreshCSRFTokens=()=>{const t=csrfToken();const e=csrfParam();if(t&&e)return $('form input[name="'+e+'"]').forEach((e=>e.value=t))};const p={"*":"*/*",text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript",script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"};const ajax=t=>{t=prepareOptions(t);var e=createXHR(t,(function(){const n=processResponse(e.response!=null?e.response:e.responseText,e.getResponseHeader("Content-Type"));Math.floor(e.status/100)===2?typeof t.success==="function"&&t.success(n,e.statusText,e):typeof t.error==="function"&&t.error(n,e.statusText,e);return typeof t.complete==="function"?t.complete(e,e.statusText):void 0}));return!(t.beforeSend&&!t.beforeSend(e,t))&&(e.readyState===XMLHttpRequest.OPENED?e.send(t.data):void 0)};var prepareOptions=function(t){t.url=t.url||location.href;t.type=t.type.toUpperCase();t.type==="GET"&&t.data&&(t.url.indexOf("?")<0?t.url+="?"+t.data:t.url+="&"+t.data);t.dataType in p||(t.dataType="*");t.accept=p[t.dataType];t.dataType!=="*"&&(t.accept+=", */*; q=0.01");return t};var createXHR=function(t,e){const n=new XMLHttpRequest;n.open(t.type,t.url,true);n.setRequestHeader("Accept",t.accept);typeof t.data==="string"&&n.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");if(!t.crossDomain){n.setRequestHeader("X-Requested-With","XMLHttpRequest");CSRFProtection(n)}n.withCredentials=!!t.withCredentials;n.onreadystatechange=function(){if(n.readyState===XMLHttpRequest.DONE)return e(n)};return n};var processResponse=function(t,e){if(typeof t==="string"&&typeof e==="string")if(e.match(/\bjson\b/))try{t=JSON.parse(t)}catch(t){}else if(e.match(/\b(?:java|ecma)script\b/)){const e=document.createElement("script");e.setAttribute("nonce",cspNonce());e.text=t;document.head.appendChild(e).parentNode.removeChild(e)}else if(e.match(/\b(xml|html|svg)\b/)){const n=new DOMParser;e=e.replace(/;.+/,"");try{t=n.parseFromString(t,e)}catch(t){}}return t};const href=t=>t.href;const isCrossDomain=function(t){const e=document.createElement("a");e.href=location.href;const n=document.createElement("a");try{n.href=t;return!((!n.protocol||n.protocol===":")&&!n.host||e.protocol+"//"+e.host===n.protocol+"//"+n.host)}catch(t){return true}};let f;let{CustomEvent:b}=window;if(typeof b!=="function"){b=function(t,e){const n=document.createEvent("CustomEvent");n.initCustomEvent(t,e.bubbles,e.cancelable,e.detail);return n};b.prototype=window.Event.prototype;({preventDefault:f}=b.prototype);b.prototype.preventDefault=function(){const t=f.call(this);this.cancelable&&!this.defaultPrevented&&Object.defineProperty(this,"defaultPrevented",{get(){return true}});return t}}const fire=(t,e,n)=>{const o=new b(e,{bubbles:true,cancelable:true,detail:n});t.dispatchEvent(o);return!o.defaultPrevented};const stopEverything=t=>{fire(t.target,"ujs:everythingStopped");t.preventDefault();t.stopPropagation();t.stopImmediatePropagation()};const delegate=(t,e,n,o)=>t.addEventListener(n,(function(t){let{target:n}=t;while(!!(n instanceof Element)&&!matches(n,e))n=n.parentNode;if(n instanceof Element&&o.call(n,t)===false){t.preventDefault();t.stopPropagation()}}));const toArray=t=>Array.prototype.slice.call(t);const serializeElement=(t,e)=>{let n=[t];matches(t,"form")&&(n=toArray(t.elements));const o=[];n.forEach((function(t){t.name&&!t.disabled&&(matches(t,"fieldset[disabled] *")||(matches(t,"select")?toArray(t.options).forEach((function(e){e.selected&&o.push({name:t.name,value:e.value})})):(t.checked||["radio","checkbox","submit"].indexOf(t.type)===-1)&&o.push({name:t.name,value:t.value})))}));e&&o.push(e);return o.map((function(t){return t.name?`${encodeURIComponent(t.name)}=${encodeURIComponent(t.value)}`:t})).join("&")};const formElements=(t,e)=>matches(t,"form")?toArray(t.elements).filter((t=>matches(t,e))):toArray(t.querySelectorAll(e));const handleConfirmWithRails=t=>function(e){allowAction(this,t)||stopEverything(e)};const confirm=(t,e)=>window.confirm(t);var allowAction=function(t,e){let n;const o=t.getAttribute("data-confirm");if(!o)return true;let a=false;if(fire(t,"confirm")){try{a=e.confirm(o,t)}catch(t){}n=fire(t,"confirm:complete",[a])}return a&&n};const handleDisabledElement=function(t){const e=this;e.disabled&&stopEverything(t)};const enableElement=t=>{let e;if(t instanceof Event){if(isXhrRedirect(t))return;e=t.target}else e=t;if(!isContentEditable(e))return matches(e,i)?enableLinkElement(e):matches(e,u)||matches(e,c)?enableFormElement(e):matches(e,o)?enableFormElements(e):void 0};const disableElement=t=>{const e=t instanceof Event?t.target:t;if(!isContentEditable(e))return matches(e,i)?disableLinkElement(e):matches(e,u)||matches(e,r)?disableFormElement(e):matches(e,o)?disableFormElements(e):void 0};var disableLinkElement=function(t){if(getData(t,"ujs:disabled"))return;const e=t.getAttribute("data-disable-with");if(e!=null){setData(t,"ujs:enable-with",t.innerHTML);t.innerHTML=e}t.addEventListener("click",stopEverything);return setData(t,"ujs:disabled",true)};var enableLinkElement=function(t){const e=getData(t,"ujs:enable-with");if(e!=null){t.innerHTML=e;setData(t,"ujs:enable-with",null)}t.removeEventListener("click",stopEverything);return setData(t,"ujs:disabled",null)};var disableFormElements=t=>formElements(t,r).forEach(disableFormElement);var disableFormElement=function(t){if(getData(t,"ujs:disabled"))return;const e=t.getAttribute("data-disable-with");if(e!=null)if(matches(t,"button")){setData(t,"ujs:enable-with",t.innerHTML);t.innerHTML=e}else{setData(t,"ujs:enable-with",t.value);t.value=e}t.disabled=true;return setData(t,"ujs:disabled",true)};var enableFormElements=t=>formElements(t,c).forEach((t=>enableFormElement(t)));var enableFormElement=function(t){const e=getData(t,"ujs:enable-with");if(e!=null){matches(t,"button")?t.innerHTML=e:t.value=e;setData(t,"ujs:enable-with",null)}t.disabled=false;return setData(t,"ujs:disabled",null)};var isXhrRedirect=function(t){const e=t.detail?t.detail[0]:void 0;return e&&e.getResponseHeader("X-Xhr-Redirect")};const handleMethodWithRails=t=>function(e){const n=this;const o=n.getAttribute("data-method");if(!o)return;if(isContentEditable(this))return;const a=t.href(n);const r=csrfToken();const c=csrfParam();const s=document.createElement("form");let i=`<input name='_method' value='${o}' type='hidden' />`;c&&r&&!isCrossDomain(a)&&(i+=`<input name='${c}' value='${r}' type='hidden' />`);i+='<input type="submit" />';s.method="post";s.action=a;s.target=n.target;s.innerHTML=i;s.style.display="none";document.body.appendChild(s);s.querySelector('[type="submit"]').click();stopEverything(e)};const isRemote=function(t){const e=t.getAttribute("data-remote");return e!=null&&e!=="false"};const handleRemoteWithRails=t=>function(a){let r,c,s;const i=this;if(!isRemote(i))return true;if(!fire(i,"ajax:before")){fire(i,"ajax:stopped");return false}if(isContentEditable(i)){fire(i,"ajax:stopped");return false}const u=i.getAttribute("data-with-credentials");const l=i.getAttribute("data-type")||"script";if(matches(i,o)){const t=getData(i,"ujs:submit-button");c=getData(i,"ujs:submit-button-formmethod")||i.getAttribute("method")||"get";s=getData(i,"ujs:submit-button-formaction")||i.getAttribute("action")||location.href;c.toUpperCase()==="GET"&&(s=s.replace(/\?.*$/,""));if(i.enctype==="multipart/form-data"){r=new FormData(i);t!=null&&r.append(t.name,t.value)}else r=serializeElement(i,t);setData(i,"ujs:submit-button",null);setData(i,"ujs:submit-button-formmethod",null);setData(i,"ujs:submit-button-formaction",null)}else if(matches(i,e)||matches(i,n)){c=i.getAttribute("data-method");s=i.getAttribute("data-url");r=serializeElement(i,i.getAttribute("data-params"))}else{c=i.getAttribute("data-method");s=t.href(i);r=i.getAttribute("data-params")}ajax({type:c||"GET",url:s,data:r,dataType:l,beforeSend(t,e){if(fire(i,"ajax:beforeSend",[t,e]))return fire(i,"ajax:send",[t]);fire(i,"ajax:stopped");return false},success(...t){return fire(i,"ajax:success",t)},error(...t){return fire(i,"ajax:error",t)},complete(...t){return fire(i,"ajax:complete",t)},crossDomain:isCrossDomain(s),withCredentials:u!=null&&u!=="false"});stopEverything(a)};const formSubmitButtonClick=function(t){const e=this;const{form:n}=e;if(n){e.name&&setData(n,"ujs:submit-button",{name:e.name,value:e.value});setData(n,"ujs:formnovalidate-button",e.formNoValidate);setData(n,"ujs:submit-button-formaction",e.getAttribute("formaction"));return setData(n,"ujs:submit-button-formmethod",e.getAttribute("formmethod"))}};const preventInsignificantClick=function(t){const e=this;const n=(e.getAttribute("data-method")||"GET").toUpperCase();const o=e.getAttribute("data-params");const a=t.metaKey||t.ctrlKey;const r=a&&n==="GET"&&!o;const c=t.button!=null&&t.button!==0;(c||r)&&t.stopImmediatePropagation()};const h={$:$,ajax:ajax,buttonClickSelector:e,buttonDisableSelector:u,confirm:confirm,cspNonce:cspNonce,csrfToken:csrfToken,csrfParam:csrfParam,CSRFProtection:CSRFProtection,delegate:delegate,disableElement:disableElement,enableElement:enableElement,fileInputSelector:s,fire:fire,formElements:formElements,formEnableSelector:c,formDisableSelector:r,formInputClickSelector:a,formSubmitButtonClick:formSubmitButtonClick,formSubmitSelector:o,getData:getData,handleDisabledElement:handleDisabledElement,href:href,inputChangeSelector:n,isCrossDomain:isCrossDomain,linkClickSelector:t,linkDisableSelector:i,loadCSPNonce:loadCSPNonce,matches:matches,preventInsignificantClick:preventInsignificantClick,refreshCSRFTokens:refreshCSRFTokens,serializeElement:serializeElement,setData:setData,stopEverything:stopEverything};const y=handleConfirmWithRails(h);h.handleConfirm=y;const j=handleMethodWithRails(h);h.handleMethod=j;const v=handleRemoteWithRails(h);h.handleRemote=v;const start=function(){if(window._rails_loaded)throw new Error("rails-ujs has already been loaded!");window.addEventListener("pageshow",(function(){$(c).forEach((function(t){getData(t,"ujs:disabled")&&enableElement(t)}));$(i).forEach((function(t){getData(t,"ujs:disabled")&&enableElement(t)}))}));delegate(document,i,"ajax:complete",enableElement);delegate(document,i,"ajax:stopped",enableElement);delegate(document,u,"ajax:complete",enableElement);delegate(document,u,"ajax:stopped",enableElement);delegate(document,t,"click",preventInsignificantClick);delegate(document,t,"click",handleDisabledElement);delegate(document,t,"click",y);delegate(document,t,"click",disableElement);delegate(document,t,"click",v);delegate(document,t,"click",j);delegate(document,e,"click",preventInsignificantClick);delegate(document,e,"click",handleDisabledElement);delegate(document,e,"click",y);delegate(document,e,"click",disableElement);delegate(document,e,"click",v);delegate(document,n,"change",handleDisabledElement);delegate(document,n,"change",y);delegate(document,n,"change",v);delegate(document,o,"submit",handleDisabledElement);delegate(document,o,"submit",y);delegate(document,o,"submit",v);delegate(document,o,"submit",(t=>setTimeout((()=>disableElement(t)),13)));delegate(document,o,"ajax:send",disableElement);delegate(document,o,"ajax:complete",enableElement);delegate(document,a,"click",preventInsignificantClick);delegate(document,a,"click",handleDisabledElement);delegate(document,a,"click",y);delegate(document,a,"click",formSubmitButtonClick);document.addEventListener("DOMContentLoaded",refreshCSRFTokens);document.addEventListener("DOMContentLoaded",loadCSPNonce);return window._rails_loaded=true};h.start=start;if(typeof jQuery!=="undefined"&&jQuery&&jQuery.ajax){if(jQuery.rails)throw new Error("If you load both jquery_ujs and rails-ujs, use rails-ujs only.");jQuery.rails=h;jQuery.ajaxPrefilter((function(t,e,n){if(!t.crossDomain)return CSRFProtection(n)}))}export{h as default};
2
+ //# sourceMappingURL=rails-ujs.esm.js.map
@@ -4,21 +4,13 @@
4
4
  .row
5
5
  - section.fields.each do |field|
6
6
  %div{ class: section.column_class }
7
- - case field.type
8
- - when :association, :belongs_to_association, :has_many_association, :has_many_through_association, :has_and_belongs_to_many_reflection, :has_one_through_association
9
- - reflection = @f.object.class.reflect_on_association(field.sym)
10
- - controllers = "#{field.type}-#{@resource.class.name.underscore.gsub('/', '_')}-#{field.sym} input-control-association"
11
- - begin
12
- - collection_path = polymorphic_path(@resource.class.reflect_on_association(field.sym).klass, format: :json)
13
- - rescue
14
- - collection_path = ''
15
- - collection = @f.object.send(field.sym)
16
- - case field.type
17
- - when :has_one_through_association
18
- = @f.input field.sym, selected: collection, collection: [collection].flatten, disabled: !field.editable, input_html: { data: { collection_path: collection_path, controller: controllers } }
19
- -else
20
- = @f.association field.sym, collection: [collection].flatten, disabled: !field.editable, input_html: { data: { collection_path: collection_path, controller: controllers } }
21
- - when :boolean
7
+ - if association?(field)
8
+ - collection = collection_for(field)
9
+ - if one_through?(field)
10
+ = @f.input field.sym, collection: [collection].flatten, disabled: !field.editable, input_html: { data: association_data_hash_for(field) }, selected: collection
11
+ - else
12
+ = @f.association field.sym, collection: [collection].flatten, disabled: !field.editable, input_html: { data: association_data_hash_for(field) }
13
+ - elsif boolean?(field)
22
14
  = @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, input_html: { data: { controller: "input-control-#{field.type}" } }, wrapper: :checkbox
23
15
  - else
24
16
  = @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, input_html: { rows: 10, data: { controller: "input-control-#{field.type}" } }
@@ -8,4 +8,53 @@ class Olivander::Components::ResourceFormComponent < ViewComponent::Base
8
8
  @f = form_builder
9
9
  super
10
10
  end
11
+
12
+ def collection_for(field)
13
+ @f.object.send(field.sym)
14
+ end
15
+
16
+ def association_data_hash_for(field)
17
+ {
18
+ collection_path: collection_path_for(field),
19
+ controller: "association-#{@resource.class.name.underscore.dasherize.gsub('/', '-')}-#{field.sym} input-control-association",
20
+ taggable: taggable?(field),
21
+ tag_field_name: tag_field_name(field)
22
+ }
23
+ end
24
+
25
+ def taggable?(field)
26
+ method_key = "#{field.sym}_taggable?"
27
+ puts method_key
28
+ return false unless @resource.class.respond_to?(method_key)
29
+
30
+ @resource.class.send(method_key)
31
+ end
32
+
33
+ def tag_field_name(field)
34
+ return '' unless taggable?(field)
35
+
36
+ @resource.class.send("#{field.sym}_tag_field_name")
37
+ end
38
+
39
+ def collection_path_for(field)
40
+ begin
41
+ polymorphic_path(@resource.class.reflect_on_association(field.sym).klass, format: :json)
42
+ rescue
43
+ ''
44
+ end
45
+ end
46
+
47
+ def association?(field)
48
+ %i[
49
+ association belongs_to_association has_many_association has_many_through_association has_and_belongs_to_many_reflection has_one_through_association
50
+ ].include?(field.type)
51
+ end
52
+
53
+ def one_through?(field)
54
+ field.type == :has_one_through_association
55
+ end
56
+
57
+ def boolean?(field)
58
+ field.type == :boolean
59
+ end
11
60
  end
@@ -6,6 +6,7 @@ module Olivander
6
6
  included do
7
7
  include Effective::CrudController
8
8
  layout 'olivander/adminlte/main'
9
+ before_action :fix_date_params
9
10
 
10
11
  def index
11
12
  if request.format == :json && params[:_type].present? && params[:_type] == 'query'
@@ -17,6 +18,25 @@ module Olivander
17
18
 
18
19
  def index_search
19
20
  self.resources ||= resource_scope.all if resource_scope.respond_to?(:all)
21
+ index_term_search if params[:term].present?
22
+ index_param_search
23
+ if resources.order_values.size.zero? && resources.model.implicit_order_column.present?
24
+ self.resources = resources.order(resources.model.implicit_order_column.to_sym)
25
+ end
26
+ self.resources = self.resources.limit(25)
27
+ end
28
+
29
+ def index_param_search
30
+ params.each do |param|
31
+ effective_resource.klass.columns.each do |col|
32
+ next unless col.name == param[0] #&& !param[1].blank?
33
+
34
+ self.resources = self.resources.where(param[0].to_sym => param[1])
35
+ end
36
+ end
37
+ end
38
+
39
+ def index_term_search
20
40
  if resource_scope.respond_to?(:search_for)
21
41
  self.resources = self.resources.search_for(params[:term])
22
42
  else
@@ -31,7 +51,6 @@ module Olivander
31
51
  self.resources = self.resources.where(clauses) if clauses.present? && clauses.length.positive?
32
52
  self.resources = self.resources.order(orders) if orders.length.positive?
33
53
  end
34
- self.resources = self.resources.limit(25)
35
54
  end
36
55
 
37
56
  def permitted_params
@@ -73,8 +92,8 @@ module Olivander
73
92
  render(action) # action.js.erb
74
93
  end
75
94
 
76
- format.turbo_stream do
77
- end
95
+ format.json { render json: resource }
96
+ format.turbo_stream {}
78
97
  end
79
98
  else # Default
80
99
  respond_to do |format|
@@ -88,11 +107,78 @@ module Olivander
88
107
  render(:member_action, locals: { action: action })
89
108
  end
90
109
 
91
- format.turbo_stream do
110
+ format.json { render json: resource }
111
+ format.turbo_stream {}
112
+ end
113
+ end
114
+ end
115
+
116
+ def respond_with_error(resource, action)
117
+ return if response.body.present?
118
+
119
+ flash.delete(:success)
120
+ flash.now[:danger] ||= resource_flash(:danger, resource, action)
121
+
122
+ respond_to do |format|
123
+ case action_name.to_sym
124
+ when :create
125
+ format.html { render :new }
126
+ when :update
127
+ format.html { render :edit }
128
+ when :destroy
129
+ format.html do
130
+ redirect_flash
131
+ redirect_to(resource_redirect_path(resource, action))
92
132
  end
133
+ else
134
+ if template_present?(action)
135
+ format.html { render(action, locals: { action: action }) }
136
+ elsif request.referer.to_s.end_with?('/edit')
137
+ format.html { render :edit }
138
+ elsif request.referer.to_s.end_with?('/new')
139
+ format.html { render :new }
140
+ else
141
+ format.html do
142
+ redirect_flash
143
+ redirect_to(resource_redirect_path(resource, action))
144
+ end
145
+ end
146
+ end
147
+
148
+ format.js do
149
+ view = template_present?(action) ? action : :member_action
150
+ render(view, locals: { action: action }) # action.js.erb
151
+ end
152
+
153
+ format.turbo_stream do
154
+ end
155
+ end
156
+ end
157
+
158
+ def date_params
159
+ []
160
+ end
161
+
162
+ def fix_date_params
163
+ recurse_and_fix_date_params(params)
164
+ end
165
+
166
+ def recurse_and_fix_date_params(params)
167
+ params.keys.each do |k|
168
+ if params[k].is_a? ActionController::Parameters
169
+ recurse_and_fix_date_params(params[k])
170
+ else
171
+ params[k] = rearrange_date_param(params[k]) if date_params.include?(k.to_sym)
93
172
  end
94
173
  end
95
174
  end
175
+
176
+ def rearrange_date_param(value)
177
+ return nil if value.blank?
178
+
179
+ parts = value.split('/')
180
+ "#{parts[2]}-#{parts[0]}-#{parts[1]}"
181
+ end
96
182
  end
97
183
  end
98
184
  end
@@ -2,6 +2,8 @@
2
2
  - @resource = instance_variable_get('@' + resource.name) if resource.name
3
3
 
4
4
  - if @resource
5
+ = render_optional_partial 'form_before'
5
6
  .row
6
7
  .col-12{ data: { controller: [controller.class.name.gsub('Controller', '').underscore.dasherize.gsub('/', '--'), action_name].join('-') } }
7
8
  = render_resource_form(@resource)
9
+ = render_optional_partial 'form_after'
@@ -125,7 +125,7 @@ SimpleForm.setup do |config|
125
125
  b.optional :min_max
126
126
  b.optional :readonly
127
127
  b.use :input, class: 'custom-control-input'
128
- #b.use :label, class: 'custom-control-label'
128
+ b.use :label, class: 'custom-control-label'
129
129
  b.use :hint, wrap_with: { tag: :span, class: :hint }
130
130
  b.use :error, wrap_with: { tag: :span, class: "text-danger" }
131
131
  end
@@ -205,7 +205,7 @@ SimpleForm.setup do |config|
205
205
  # config.wrapper_mappings = { string: :prepend }
206
206
  config.wrapper_mappings = {
207
207
  boolean: :vertical_boolean,
208
- check_boxes: :check_box,
208
+ check_boxes: :vertical_collection,
209
209
  # date: :horizontal_multi_select,
210
210
  # datetime: :horizontal_multi_select,
211
211
  # file: :horizontal_file,
@@ -1,3 +1,3 @@
1
1
  module Olivander
2
- VERSION = '0.2.0.6'.freeze
2
+ VERSION = '0.2.0.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: five-two-nw-olivander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.6
4
+ version: 0.2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-21 00:00:00.000000000 Z
11
+ date: 2024-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick
@@ -217,6 +217,7 @@ files:
217
217
  - app/assets/javascripts/controllers/modal_controller.js
218
218
  - app/assets/javascripts/controllers/turbo_flash_controller.js
219
219
  - app/assets/javascripts/olivander/flash_toast.js
220
+ - app/assets/javascripts/olivander/rails-ujs.esm.js
220
221
  - app/assets/stylesheets/adminlte.css
221
222
  - app/assets/stylesheets/fa-fix.scss
222
223
  - app/assets/stylesheets/olivander/application.css