Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improve custom fields performance (WIP) #1031

Open
wants to merge 13 commits into
base: feature/version-3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 31 additions & 37 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
## BUILDING
## (from project root directory)
## $ docker build -t owen2345-camaleon-cms .
##
## RUNNING
## $ docker run -p 3000:3000 owen2345-camaleon-cms
##
## CONNECTING
## Lookup the IP of your active docker host using:
## $ docker-machine ip $(docker-machine active)
## Connect to the container at DOCKER_IP:3000
## replacing DOCKER_IP for the IP of your active docker host

FROM gcr.io/stacksmith-images/ubuntu-buildpack:14.04-r07

MAINTAINER Bitnami <[email protected]>

ENV STACKSMITH_STACK_ID="ujruqvm" \
STACKSMITH_STACK_NAME="owen2345/camaleon-cms" \
STACKSMITH_STACK_PRIVATE="1"

RUN bitnami-pkg install ruby-2.3.1-1 --checksum a81395976c85e8b7c8da3c1db6385d0e909bd05d9a3c1527f8fa36b8eb093d84

ENV PATH=/opt/bitnami/ruby/bin:$PATH

## STACKSMITH-END: Modifications below this line will be unchanged when regenerating

# Ruby on Rails template
ENV RAILS_ENV=development

COPY Gemfile* /app/
FROM ruby:3.1-slim as builder
RUN apt-get update && apt-get install curl gnupg build-essential libpq-dev -y
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq
RUN apt install yarn -y
RUN apt-get install imagemagick -y

RUN mkdir /app
WORKDIR /app

RUN bundle install --without production

COPY . /app

# Default port and web server command
EXPOSE 3000

CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", "3000"]
CMD ["bundle exec rspec"]

##################################### (Development)
# install google chrome
RUN apt-get install wget -y
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get install -y google-chrome-stable

# install chromedriver
RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/

#COPY package.json yarn.lock /app/
#RUN yarn install
COPY Gemfile* camaleon_cms.gemspec /app/
COPY lib/camaleon_cms/version.rb /app/lib/camaleon_cms/
RUN bundle install --jobs 20 --retry 5
COPY . /app
2 changes: 1 addition & 1 deletion app/decorators/camaleon_cms/category_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def generate_breadcrumb(add_post_type = true, is_parent = false)
if _parent.present?
_parent.decorate.generate_breadcrumb(add_post_type, true)
else
object.post_type_parent.decorate.generate_breadcrumb(add_post_type, true)
object.post_type.decorate.generate_breadcrumb(add_post_type, true)
end
h.breadcrumb_add(self.the_title, is_parent ? self.the_url : nil)
end
Expand Down
77 changes: 42 additions & 35 deletions app/helpers/camaleon_cms/admin/custom_fields_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#encoding: utf-8
module CamaleonCms::Admin::CustomFieldsHelper
def cama_custom_field_elements
return @_cama_custom_field_elements if @_cama_custom_field_elements.present?

def cama_custom_field_settings
items = {}
items[:text_box] = {
key: 'text_box',
label: t('camaleon_cms.admin.custom_field.fields.text_box'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.text_box'),
options: {
required: true,
multiple: true,
Expand All @@ -17,7 +17,7 @@ def cama_custom_field_elements

items[:text_area] = {
key: 'text_area',
label: t('camaleon_cms.admin.custom_field.fields.text_area'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.text_area'),
options: {
required: true,
multiple: true,
Expand All @@ -28,26 +28,26 @@ def cama_custom_field_elements
}
items[:select] = {
key: 'select',
label: t('camaleon_cms.admin.custom_field.fields.select'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.select'),
options: {
required: true,
multiple: true,
translate: true,
multiple_options: {
label: t('camaleon_cms.admin.settings.options_select'),
label: I18n.t('camaleon_cms.admin.settings.options_select'),
default: 'radio'
},
show_frontend: true
}
}
items[:radio] = {
key: 'radio',
label: t('camaleon_cms.admin.custom_field.fields.radio', default: 'Radio'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.radio', default: 'Radio'),
options: {
required: true,
multiple: false,
multiple_options: {
label: t('camaleon_cms.admin.settings.options_select'),
label: I18n.t('camaleon_cms.admin.settings.options_select'),
default: 'radio',
use_not_default: true
},
Expand All @@ -57,7 +57,7 @@ def cama_custom_field_elements

items[:checkbox] = {
key: 'checkbox',
label: t('camaleon_cms.admin.custom_field.fields.checkbox', default: 'Checkbox'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.checkbox', default: 'Checkbox'),
options: {
required: true,
multiple: false,
Expand All @@ -67,7 +67,7 @@ def cama_custom_field_elements
}
items[:checkboxes] = {
key: 'checkboxes',
label: t('camaleon_cms.admin.custom_field.fields.checkboxes', default: 'Checkboxes'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.checkboxes', default: 'Checkboxes'),
options: {
required: false,
multiple: false,
Expand All @@ -80,7 +80,7 @@ def cama_custom_field_elements
}
items[:audio] = {
key: 'audio',
label: t('camaleon_cms.admin.custom_field.fields.audio', default: 'Audio'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.audio', default: 'Audio'),
options: {
required: true,
multiple: true,
Expand All @@ -90,7 +90,7 @@ def cama_custom_field_elements
}
items[:colorpicker] = {
key: 'colorpicker',
label: t('camaleon_cms.admin.custom_field.fields.colorpicker'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.colorpicker'),
extra_fields:[
{
type: 'select',
Expand Down Expand Up @@ -121,19 +121,19 @@ def cama_custom_field_elements
}
items[:date] = {
key: 'date',
label: t('camaleon_cms.admin.custom_field.fields.date'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.date'),
extra_fields:[
{
type: 'radio',
key: 'type_date',
values: [
{
value: '0',
label: t('camaleon_cms.admin.settings.input_only_date')
label: I18n.t('camaleon_cms.admin.settings.input_only_date')
},
{
value: '1',
label: t('camaleon_cms.admin.settings.input_date_time')
label: I18n.t('camaleon_cms.admin.settings.input_date_time')
}
]
}
Expand All @@ -147,7 +147,7 @@ def cama_custom_field_elements
}
items[:editor] = {
key: 'editor',
label: t('camaleon_cms.admin.custom_field.fields.editor', default: 'Editor'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.editor', default: 'Editor'),
options: {
required: false,
multiple: true,
Expand All @@ -158,7 +158,7 @@ def cama_custom_field_elements
}
items[:email] = {
key: 'email',
label: t('camaleon_cms.admin.custom_field.fields.email'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.email'),
options: {
required: true,
multiple: true,
Expand All @@ -168,7 +168,7 @@ def cama_custom_field_elements
}
items[:file] = {
key: 'file',
label: t('camaleon_cms.admin.custom_field.fields.file'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.file'),
options: {
required: true,
multiple: true,
Expand All @@ -185,7 +185,7 @@ def cama_custom_field_elements
}
items[:image] = {
key: 'image',
label: t('camaleon_cms.admin.custom_field.fields.image'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.image'),
options: {
required: true,
multiple: true,
Expand All @@ -196,20 +196,20 @@ def cama_custom_field_elements
{
type: 'text_box',
key: 'dimension',
label: cama_t('camaleon_cms.admin.custom_field.fields.image_dimension'),
description: cama_t('camaleon_cms.admin.custom_field.fields.image_dimension_descr'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.image_dimension'),
description: I18n.t('camaleon_cms.admin.custom_field.fields.image_dimension_descr'),
},
{
type: 'text_box',
key: 'versions',
label: cama_t('camaleon_cms.admin.custom_field.fields.image_versions'),
description: cama_t('camaleon_cms.admin.custom_field.fields.image_versions_descr')
label: I18n.t('camaleon_cms.admin.custom_field.fields.image_versions'),
description: I18n.t('camaleon_cms.admin.custom_field.fields.image_versions_descr')
}
]
}
items[:numeric] = {
key: 'numeric',
label: t('camaleon_cms.admin.custom_field.fields.numeric'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.numeric'),
options: {
required: true,
multiple: true,
Expand All @@ -219,7 +219,7 @@ def cama_custom_field_elements
}
items[:phone] = {
key: 'phone',
label: t('camaleon_cms.admin.custom_field.fields.phone'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.phone'),
options: {
required: true,
multiple: true,
Expand All @@ -229,7 +229,7 @@ def cama_custom_field_elements
}
items[:url] = {
key: 'url',
label: t('camaleon_cms.admin.custom_field.fields.url', default: 'URL'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.url', default: 'URL'),
options: {
required: true,
multiple: true,
Expand All @@ -240,7 +240,7 @@ def cama_custom_field_elements
}
items[:video] = {
key: 'video',
label: t('camaleon_cms.admin.custom_field.fields.video', default: 'Video'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.video', default: 'Video'),
options: {
required: true,
multiple: true,
Expand All @@ -250,7 +250,7 @@ def cama_custom_field_elements
}
items[:users] = {
key: 'users',
label: t('camaleon_cms.admin.custom_field.fields.users'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.users'),
options: {
required: true,
multiple: true,
Expand All @@ -259,7 +259,7 @@ def cama_custom_field_elements
}
items[:posts] = {
key: 'posts',
label: t('camaleon_cms.admin.custom_field.fields.posts'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.posts'),
options: {
required: true,
multiple: true,
Expand All @@ -277,7 +277,7 @@ def cama_custom_field_elements

items[:post_types] = {
key: 'post_types',
label: t('camaleon_cms.admin.post_type.post_types'),
label: I18n.t('camaleon_cms.admin.post_type.post_types'),
options: {
required: true,
multiple: true
Expand All @@ -286,7 +286,7 @@ def cama_custom_field_elements

items[:categories] = {
key: 'categories',
label: t('camaleon_cms.admin.table.categories'),
label: I18n.t('camaleon_cms.admin.table.categories'),
options: {
required: true,
multiple: true
Expand All @@ -297,7 +297,7 @@ def cama_custom_field_elements
# sample command: options_from_collection_for_select(current_site.the_posts("commerce").decorate, :id, :the_title)
items[:select_eval] = {
key: 'select_eval',
label: t('camaleon_cms.admin.custom_field.fields.select_eval'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.select_eval'),
options: {
required: true,
multiple: false,
Expand All @@ -314,7 +314,7 @@ def cama_custom_field_elements
}
items[:field_attrs] = {
key: 'field_attrs',
label: t('camaleon_cms.admin.custom_field.fields.field_attrs'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.field_attrs'),
options: {
required: false,
multiple: true,
Expand All @@ -324,7 +324,7 @@ def cama_custom_field_elements
}
items[:private_file] = {
key: 'private_file',
label: t('camaleon_cms.admin.custom_field.fields.private_file', default: 'Private File'),
label: I18n.t('camaleon_cms.admin.custom_field.fields.private_file', default: 'Private File'),
options: {
required: true,
multiple: true,
Expand All @@ -338,7 +338,14 @@ def cama_custom_field_elements
}
]
}
r = {fields: items}; hooks_run("extra_custom_fields", r)
items
end
module_function :cama_custom_field_settings

def cama_custom_field_elements
return @_cama_custom_field_elements if @_cama_custom_field_elements.present?

r = {fields: cama_custom_field_settings}; hooks_run("extra_custom_fields", r)
@_cama_custom_field_elements = r[:fields]
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/camaleon_cms/admin/post_type_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module CamaleonCms::Admin::PostTypeHelper
#taxonomy -> (categories || post_tags)
def post_type_html_inputs(post_type, taxonomy="categories", name ="categories", type="checkbox", values=[], class_cat="categorychecklist" , required = false)
categories = post_type.send(taxonomy)
categories = categories.eager_load(:children, :post_type_parent, :parent) if taxonomy == "categories" || taxonomy == "children"
categories = categories.eager_load(:children, :post_type, :parent) if taxonomy == "categories" || taxonomy == "children"
post_type_taxonomy_html_(categories,taxonomy, name, type, values, class_cat, required)
end

Expand Down
Loading