Skip to content

Commit

Permalink
Merge pull request #107 from finnlabs/feature/attachments_on_new_reso…
Browse files Browse the repository at this point in the history
…urce

Feature/attachments on new resource

[ci skip]
  • Loading branch information
oliverguenther authored Aug 2, 2018
2 parents e957ba4 + 3de8899 commit e02aa6c
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 170 deletions.
23 changes: 3 additions & 20 deletions app/controllers/my_projects_overviews_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def update_custom_element
block_title: block_title,
block_name: block_name,
textile: textile })
else
render plain: t(:error_textile_not_saved), status: 400
end
else
render plain: t(:error_textile_not_saved), status: 400
end
end

# Add a block to user's page
Expand Down Expand Up @@ -88,23 +88,6 @@ def save_changes
end
end

def render_attachments
render partial: 'page_layout_attachments'
end

def destroy_attachment
if user.allowed_to?(:edit_project, project)
begin
att = Attachment.find(params[:attachment_id].to_i)
overview.attachments.delete(att)
overview.save
rescue ActiveRecord::RecordNotFound
end
end

render partial: 'page_layout_attachments'
end

helper_method :project,
:user,
:overview
Expand Down
3 changes: 0 additions & 3 deletions app/helpers/my_projects_overviews_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#++

module MyProjectsOverviewsHelper

def top_fields
%w(top)
end
Expand Down Expand Up @@ -74,8 +73,6 @@ def recent_news
.limit(5)
end



def attachments
@attachments = overview.attachments || []
end
Expand Down
10 changes: 6 additions & 4 deletions app/models/my_projects_overview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class MyProjectsOverview < ActiveRecord::Base
after_initialize :initialize_default_values

DEFAULTS = {
"left" => ["project_description", "project_details", "work_package_tracking"],
"right" => ["members", "news_latest"],
"left" => %w(project_description project_details work_package_tracking),
"right" => %w(members news_latest),
"top" => [],
"hidden" => []
}
}.freeze

def initialize_default_values
# attributes() creates a copy every time it is called, so better not use it in a loop
Expand All @@ -50,7 +50,9 @@ def initialize_default_values

validate :fields_are_arrays

acts_as_attachable delete_permission: :edit_project, view_permission: :view_project
acts_as_attachable delete_permission: :edit_project,
view_permission: :view_project,
add_permission: :edit_project

def fields_are_arrays
Array === top && Array === left && Array === right && Array === hidden
Expand Down
5 changes: 4 additions & 1 deletion app/views/my_projects_overviews/_block.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See doc/COPYRIGHT.md for more details.
++#%>
<div id="block_<%= block_name %>" class="widget-box" overview-block block-name="<%= block_name %>">
<div id="block_<%= block_name %>" class="widget-box">

<% block_name_id = "my_page_#{block_name}_box_actions" %>
<% content_for block_name_id do %>
Expand All @@ -37,3 +37,6 @@ See doc/COPYRIGHT.md for more details.
<%= render partial: "my_projects_overviews/blocks/#{block_name}", locals: { block_name_id: block_name_id } %>
</div>
</div>

<overview-block block-name="<%= block_name %>">
</overview-block>
33 changes: 23 additions & 10 deletions app/views/my_projects_overviews/_block_textilizable.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ See doc/COPYRIGHT.md for more details.

<% new_block ||= local_assigns[:new_block] %>

<div overview-textile-block
id="block_<%= block_name %>"
<% resource = ::API::V3::Overview::OverviewRepresenter.new(overview,
current_user: current_user,
embed_links: true) %>

<div id="block_<%= block_name %>"
ng-cloak
class="widget-box block-teaser"
block-name="<%= block_name %>"
new-block="<%= !!new_block %>">
class="widget-box block-teaser">
<div class="handle" cg-busy="$ctrl.loadingIndicator">
<% content_for block_name do %>
<div id="<%= block_name %>-form-div" class="textile-form-wrapper" ng-show="$ctrl.formVisible">
Expand All @@ -49,17 +50,24 @@ See doc/COPYRIGHT.md for more details.
<%= styled_text_field_tag "block_title_#{block_name}", block_title %>
</div>
</div>

<div class="form--field -required">
<%= styled_label_tag "textile_#{block_name}", t('info_custom_text') %>
<div class="form--field-container" ng-non-bindable>
<%= styled_text_area_tag "textile_#{block_name}", textile.html_safe, cols: 40, rows: 5, class: 'wiki-edit' %>

<%= styled_text_area_tag "textile_#{block_name}",
textile.html_safe,
class: 'wiki-edit',
with_text_formatting: true,
resource: resource %>
</div>
</div>
<%= wikitoolbar_for "textile_#{block_name}" %>
<%= render partial: 'attachments/form' %>

<attachments data-resource="<%= resource.to_json %>" data-allow-uploading="true"></attachments>

<%= styled_button_tag l(:button_save),
id: "#{block_name}-form-submit",
class: '-highlight' %>
id: "#{block_name}-form-submit",
class: '-highlight' %>
<a href="#" ng-click="$ctrl.toggleEditForm(false)" class="reset-textilizable button"><%= t(:button_cancel) %></a>
<% end %>
</div>
Expand Down Expand Up @@ -87,3 +95,8 @@ See doc/COPYRIGHT.md for more details.
</div>
</div>
</div>

<overview-textile-block
block-name="<%= block_name %>"
new-block="<%= !!new_block %>">
</overview-textile-block>
34 changes: 0 additions & 34 deletions app/views/my_projects_overviews/_page_layout_attachments.html.erb

This file was deleted.

90 changes: 44 additions & 46 deletions app/views/my_projects_overviews/page_layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,57 @@ See doc/COPYRIGHT.md for more details.
<%= stylesheet_link_tag "my_project_page/my_projects_overview", media: 'all' %>
<% end %>

<%= activate_angular_js do %>
<overview-page-layout>
<%= toolbar title: l(:label_overview) do %>
<li class="toolbar-item">
<%= styled_form_tag({action: "add_block"}, id: "add-block-form") do %>
<%= styled_select_tag 'block',
options_for_select(block_options),
id: "block-select",
class: 'form--select',
:'ng-model' => '$ctrl.selectedBlock',
:'ng-change' => '$ctrl.handleBlockSelection()'
%>
<% end %>
</li>
<li class="toolbar-item">
<%= form_tag({action: "save_changes"}, id: "save-block-form", :'ng-submit' => '$ctrl.handleSaveChanges()') do %>
<% blocks.keys.each do |f| %>
<input type="hidden" name="<%= f %>" value="" />
<div id="page-layout">
<%= toolbar title: l(:label_overview) do %>
<li class="toolbar-item">
<%= styled_form_tag({action: "add_block"}, id: "add-block-form") do %>
<%= styled_select_tag 'block',
options_for_select(block_options),
id: "block-select",
class: 'form--select',
:'ng-model' => '$ctrl.selectedBlock',
:'ng-change' => '$ctrl.handleBlockSelection()'
%>
<% end %>
<%= submit_tag t(:button_save), class: 'button -alt-highlight' %>
<% end %>
</li>
<li class="toolbar-item">
<%= link_to t(:button_cancel), {action: 'index'}, class: 'button' %>
</li>
<% end %>
</li>
<li class="toolbar-item">
<%= form_tag({action: "save_changes"}, id: "save-block-form", :'ng-submit' => '$ctrl.handleSaveChanges()') do %>
<% blocks.keys.each do |f| %>
<input type="hidden" name="<%= f %>" value="" />
<% end %>
<%= submit_tag t(:button_save), class: 'button -alt-highlight' %>
<% end %>
</li>
<li class="toolbar-item">
<%= link_to t(:button_cancel), {action: 'index'}, class: 'button' %>
</li>
<% end %>

<div id="my_project_blocks">
<h3><%=l(:label_visible_elements) %></h3>
<div id="visible-grid" class="widget-boxes">
<% top_fields.each do |f| %>
<%= grid_field f %>
<% end %>

<div id="my_project_blocks">
<h3><%=l(:label_visible_elements) %></h3>
<div id="visible-grid" class="widget-boxes">
<% top_fields.each do |f| %>
<%= grid_field f %>
<% end %>
<div class="grid-block">
<% middle_fields.each do |f| %>
<%= grid_field f %>
<% end %>
</div>
</div>

<div class="grid-block">
<% middle_fields.each do |f| %>
<h3><%=l(:label_hidden_elements) %></h3>
<div class="widget-boxes">
<% hidden_fields.each do |f| %>
<%= grid_field f %>
<% end %>
</div>
</div>
</div>

<h3><%=l(:label_hidden_elements) %></h3>
<div class="widget-boxes">
<% hidden_fields.each do |f| %>
<%= grid_field f %>
<% end %>
</div>
<%= activate_angular_js do %>
<overview-page-layout>
</overview-page-layout>
<% end %>

<h3><%= l(:label_file_plural) %></h3>
<div class="attachments" id="page_layout_attachments" data-refresh-url="<%= url_for(action: 'render_attachments') %>">
<%= render(partial: "page_layout_attachments") %>
</div>
</div>
</overview-page-layout>
<% end %>
5 changes: 1 addition & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
get 'projects/:id', to: "my_projects_overviews#index" ,
constraints: { format: :html, id: Regexp.new("(?!(#{Project::RESERVED_IDENTIFIERS.join('|')})$)(\\w|-)+") }




get 'my_projects_overview/:id/page_layout', to: "my_projects_overviews#page_layout",
as: :my_projects_overview
post 'my_projects_overview/:id/page_layout/save_changes', to: "my_projects_overviews#save_changes"
post 'my_projects_overview/:id/page_layout/add_block', to: "my_projects_overviews#add_block"
put 'my_projects_overview/:id/page_layout/update_custom_element', to: "my_projects_overviews#update_custom_element"
get 'my_projects_overview/:id/page_layout/render_attachments', to: "my_projects_overviews#render_attachments"
post 'my_projects_overview/:id/page_layout/destroy_attachment', to: "my_projects_overviews#destroy_attachment"
delete 'my_projects_overview/:id/page_layout/destroy_attachment', to: "my_projects_overviews#destroy_attachment"
end
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ export class OverviewBlockController {
this.layoutCtrl.updateAvailableBlocks();
return false;
}

}

function overviewBlock():any {
function overviewBlock($compile:any):any {
return {
restrict: 'EA',
scope: {},
restrict: 'E',
scope: {
blockName: '@'
},
transclude: true,
compile: function() {
return function(
Expand All @@ -63,9 +64,12 @@ function overviewBlock():any {
attrs:ng.IAttributes,
ctrl:any,
transclude:any) {
scope.$ctrl.layoutCtrl = ctrl;

scope.$ctrl.layoutCtrl = scope.$parent.$ctrl;

transclude(scope, (clone:any) => {
element.append(clone);
let original = jQuery(`#block_${scope.$ctrl.blockName}`);
element.append($compile(original)(scope));
});
};
},
Expand Down
Loading

0 comments on commit e02aa6c

Please sign in to comment.