Skip to content

Commit

Permalink
Portfolio (#1696)
Browse files Browse the repository at this point in the history
* feature

* wip

* refactor features in traits

* add controllers

* views wip

* wip

* projects !

* done!

* fix
  • Loading branch information
arnaudlevy committed Mar 11, 2024
1 parent b3d1876 commit faebcdd
Show file tree
Hide file tree
Showing 53 changed files with 1,186 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Admin::Communication::Websites::Portfolio::ApplicationController < Admin::Communication::Websites::ApplicationController

protected

def breadcrumb
super
add_breadcrumb Communication::Website::Portfolio.model_name.human(count: 2),
admin_communication_website_portfolio_projects_path
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class Admin::Communication::Websites::Portfolio::CategoriesController < Admin::Communication::Websites::Portfolio::ApplicationController
load_and_authorize_resource class: 'Communication::Website::Portfolio::Category',
through: :website,
through_association: :portfolio_categories

include Admin::Translatable
include Admin::Categorizable

def index
@root_categories = categories.root
@categories_class = categories_class
breadcrumb
end

def show
@projects = @category.projects.ordered.page(params[:page])
breadcrumb
end

def static
@about = @category
render_as_plain_text
end

def new
breadcrumb
end

def edit
breadcrumb
add_breadcrumb t('edit')
end

def create
@category.website = @website
@category.add_photo_import params[:photo_import]
if @category.save_and_sync
redirect_to admin_communication_website_portfolio_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s)
else
breadcrumb
render :new, status: :unprocessable_entity
end
end

def update
@category.add_photo_import params[:photo_import]
if @category.update_and_sync(category_params)
redirect_to admin_communication_website_portfolio_category_path(@category), notice: t('admin.successfully_updated_html', model: @category.to_s)
else
breadcrumb
add_breadcrumb t('edit')
render :edit, status: :unprocessable_entity
end
end

def destroy
@category.destroy
redirect_to admin_communication_website_portfolio_categories_url, notice: t('admin.successfully_destroyed_html', model: @category.to_s)
end

protected

def categories_class
Communication::Website::Portfolio::Category
end

def breadcrumb
super
add_breadcrumb categories_class.model_name.human(count: 2),
admin_communication_website_portfolio_categories_path
breadcrumb_for @category
end

def category_params
params.require(:communication_website_portfolio_category)
.permit(
:name, :meta_description, :summary, :slug,
:featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit
)
.merge(
university_id: current_university.id,
language_id: current_website_language.id
)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
class Admin::Communication::Websites::Portfolio::ProjectsController < Admin::Communication::Websites::Portfolio::ApplicationController
load_and_authorize_resource class: Communication::Website::Portfolio::Project,
through: :website

include Admin::Translatable

def index
@projects = apply_scopes(@projects).for_language(current_website_language)
.ordered
.page(params[:page])
@root_categories = categories.root
@categories_class = Communication::Website::Portfolio::Category
breadcrumb
end

def publish
@project.published = true
@project.save_and_sync
redirect_back fallback_location: admin_communication_website_portfolio_project_path(@project),
notice: t('admin.communication.website.publish.notice')
end

def show
breadcrumb
end

def static
@about = @project
render_as_plain_text
end

def new
@categories = categories
breadcrumb
end

def edit
@categories = categories
breadcrumb
add_breadcrumb t('edit')
end

def create
@project.website = @website
@project.add_photo_import params[:photo_import]
if @project.save_and_sync
redirect_to admin_communication_website_portfolio_project_path(@project),
notice: t('admin.successfully_created_html', model: @project.to_s)
else
@categories = categories
breadcrumb
render :new, status: :unprocessable_entity
end
end

def update
@project.add_photo_import params[:photo_import]
if @project.update_and_sync(project_params)
redirect_to admin_communication_website_portfolio_project_path(@project),
notice: t('admin.successfully_updated_html', model: @project.to_s)
else
@categories = categories
breadcrumb
add_breadcrumb t('edit')
render :edit, status: :unprocessable_entity
end
end

def duplicate
redirect_to [:admin, @project.duplicate],
notice: t('admin.successfully_duplicated_html', model: @project.to_s)
end

def destroy
@project.destroy
redirect_to admin_communication_website_portolio_projects_url,
notice: t('admin.successfully_destroyed_html', model: @project.to_s)
end
protected

def breadcrumb
super
breadcrumb_for @project
end

def categories
@website.portfolio_categories
.for_language(current_website_language)
.ordered
end

def project_params
params.require(:communication_website_portfolio_project)
.permit(
:title, :meta_description, :summary, :published, :slug, :year,
:featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit,
category_ids: []
)
.merge(
university_id: current_university.id,
language_id: current_website_language.id
)
end
end
2 changes: 1 addition & 1 deletion app/controllers/admin/communication/websites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def website_params
attribute_names = [
:name, :url, :repository, :about_type, :about_id, :in_production,
:git_provider, :git_endpoint, :git_branch, :plausible_url,
:feature_posts, :feature_agenda,
:feature_posts, :feature_agenda, :feature_portfolio,
:default_time_zone,
:deuxfleurs_hosting, :default_image, :default_image_delete, :default_shared_image, :default_shared_image_delete,
:social_mastodon, :social_x, :social_linkedin, :social_youtube, :social_vimeo, :social_peertube, :social_instagram, :social_facebook, :social_tiktok, :social_email, :social_github,
Expand Down
4 changes: 4 additions & 0 deletions app/models/communication/website.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# deuxfleurs_hosting :boolean default(TRUE)
# deuxfleurs_identifier :string
# feature_agenda :boolean default(FALSE)
# feature_portfolio :boolean default(FALSE)
# feature_posts :boolean default(TRUE)
# git_branch :string
# git_endpoint :string
Expand Down Expand Up @@ -55,6 +56,9 @@ class Communication::Website < ApplicationRecord
self.filter_attributes += [:access_token]

include Favoritable
include FeatureAgenda
include FeatureBlog
include FeaturePortfolio
include WithAbouts
include WithAssociatedObjects
include WithConfigs
Expand Down
23 changes: 23 additions & 0 deletions app/models/communication/website/feature_agenda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Communication::Website::FeatureAgenda
extend ActiveSupport::Concern

included do
has_many :agenda_events,
class_name: "Communication::Website::Agenda::Event",
foreign_key: :communication_website_id
alias :events :agenda_events

has_many :agenda_categories,
class_name: 'Communication::Website::Agenda::Category',
foreign_key: :communication_website_id,
dependent: :destroy
end

def has_agenda_events?
agenda_events.published.any?
end

def has_agenda_categories?
agenda_categories.any?
end
end
24 changes: 24 additions & 0 deletions app/models/communication/website/feature_blog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Communication::Website::FeatureBlog
extend ActiveSupport::Concern

included do
has_many :posts,
foreign_key: :communication_website_id,
dependent: :destroy

has_many :authors, -> { distinct }, through: :posts

has_many :post_categories,
class_name: 'Communication::Website::Post::Category',
foreign_key: :communication_website_id,
dependent: :destroy
end

def has_blog_posts?
posts.published.any?
end

def has_blog_categories?
post_categories.any?
end
end
24 changes: 24 additions & 0 deletions app/models/communication/website/feature_portfolio.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Communication::Website::FeaturePortfolio
extend ActiveSupport::Concern

included do
has_many :portfolio_projects,
class_name: "Communication::Website::Portfolio::Project",
foreign_key: :communication_website_id
alias :projects :portfolio_projects

has_many :portfolio_categories,
class_name: 'Communication::Website::Portfolio::Category',
foreign_key: :communication_website_id,
dependent: :destroy
alias :projects_categories :portfolio_categories
end

def has_portfolio_projects?
projects.published.any?
end

def has_portfolio_categories?
portfolio_categories.any?
end
end
24 changes: 24 additions & 0 deletions app/models/communication/website/page/communication_portfolio.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Communication::Website::Page::CommunicationPortfolio < Communication::Website::Page

def editable_width?
false
end

def full_width_by_default?
true
end

def is_necessary_for_website?
website.feature_portfolio
end

def dependencies
super +
[website.config_default_languages] +
website.projects
end

def git_path_relative
'projects/_index.html'
end
end
1 change: 1 addition & 0 deletions app/models/communication/website/page/with_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Communication::Website::Page::WithType
Communication::Website::Page::CommunicationPost,
Communication::Website::Page::CommunicationAgenda,
Communication::Website::Page::CommunicationAgendaArchive,
Communication::Website::Page::CommunicationPortfolio,
Communication::Website::Page::Person,
Communication::Website::Page::Organization,
# Education
Expand Down
2 changes: 2 additions & 0 deletions app/models/communication/website/permalink.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Communication::Website::Permalink < ApplicationRecord
"Communication::Website::Post::Category" => Communication::Website::Permalink::Category,
"Communication::Website::Agenda::Event" => Communication::Website::Permalink::Agenda::Event,
"Communication::Website::Agenda::Category" => Communication::Website::Permalink::Agenda::Category,
"Communication::Website::Portfolio::Project" => Communication::Website::Permalink::Portfolio::Project,
"Communication::Website::Portfolio::Category" => Communication::Website::Permalink::Portfolio::Category,
"Administration::Location" => Communication::Website::Permalink::Location,
"Education::Diploma" => Communication::Website::Permalink::Diploma,
"Education::Program" => Communication::Website::Permalink::Program,
Expand Down
4 changes: 2 additions & 2 deletions app/models/communication/website/permalink/author.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Communication::Website::Permalink::Author < Communication::Website::Permalink
def self.required_in_config?(website)
# website might have authors but no communication_posts (if a post unpublished exists)
website.has_authors? && website.has_communication_posts?
# website might have authors but no posts (if a post unpublished exists)
website.has_authors? && website.has_blog_posts?
end

def self.static_config_key
Expand Down
7 changes: 6 additions & 1 deletion app/models/communication/website/permalink/category.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Ce modèle concerne les catégories de posts, qui n'ont pas de namespace
# Il pourrait y avoir un namespace, par exemple Blog.
# Si c'était le cas, le modèle devrait être nommé :
# Communication::Website::Permalink::Blog::Category
# Et il faudrait migrer en conséquence
class Communication::Website::Permalink::Category < Communication::Website::Permalink
def self.required_in_config?(website)
website.has_communication_posts? && website.has_communication_categories?
website.has_blog_posts? && website.has_blog_categories?
end

def self.static_config_key
Expand Down
27 changes: 27 additions & 0 deletions app/models/communication/website/permalink/portfolio/category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Communication::Website::Permalink::Portfolio::Category < Communication::Website::Permalink
def self.required_in_config?(website)
website.feature_portfolio
end

def self.static_config_key
:projects_categories
end

# /projets/:slug/
def self.pattern_in_website(website, language)
"/#{website.special_page(Communication::Website::Page::CommunicationPortfolio, language: language).slug_with_ancestors}/:slug/"
end

protected

def published?
website.id == about.communication_website_id
end

def substitutions
{
slug: about.slug
}
end

end
Loading

0 comments on commit faebcdd

Please sign in to comment.