parent
b8f185eaf5
commit
a3e0231c94
@ -0,0 +1,15 @@ |
||||
class CreateProjectsStorages < ActiveRecord::Migration[6.1] |
||||
def change |
||||
create_table :projects_storages do |t| |
||||
t.bigint :project_id, null: false, foreign_key: true |
||||
t.bigint :storage_id, null: false, foreign_key: true |
||||
t.bigint :creator_id, null: false, foreign_key: true |
||||
|
||||
t.timestamps |
||||
|
||||
t.index :project_id |
||||
t.index :storage_id |
||||
t.index %i[project_id storage_id], unique: true |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,33 @@ |
||||
module Storages |
||||
class ProjectsStoragesRowCell < ::RowCell |
||||
include ::IconsHelper |
||||
include ::AvatarHelper |
||||
include ::Redmine::I18n |
||||
|
||||
def name |
||||
model.storage.name |
||||
end |
||||
|
||||
def provider_type |
||||
model.storage.provider_type |
||||
end |
||||
|
||||
def creator |
||||
icon = avatar model.creator, size: :mini |
||||
icon + model.creator.name |
||||
end |
||||
|
||||
def button_links |
||||
[delete_link] |
||||
end |
||||
|
||||
def delete_link |
||||
link_to '', |
||||
project_settings_projects_storage_path(project_id: model.project, id: model), |
||||
class: 'icon icon-delete', |
||||
data: { confirm: I18n.t(:text_are_you_sure) }, |
||||
title: I18n.t(:button_delete), |
||||
method: :delete |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,43 @@ |
||||
module Storages |
||||
class ProjectsStoragesTableCell < ::TableCell |
||||
include ::IconsHelper |
||||
|
||||
class << self |
||||
def row_class |
||||
::Storages::ProjectsStoragesRowCell |
||||
end |
||||
end |
||||
|
||||
columns :name, :provider_type, :creator, :created_at |
||||
|
||||
def initial_sort |
||||
%i[created_at asc] |
||||
end |
||||
|
||||
def sortable? |
||||
false |
||||
end |
||||
|
||||
def inline_create_link |
||||
link_to(new_project_settings_projects_storage_path, |
||||
class: 'wp-inline-create--add-link', |
||||
title: I18n.t('storages.label_new_storage')) do |
||||
op_icon('icon icon-add') |
||||
end |
||||
end |
||||
|
||||
def empty_row_message |
||||
I18n.t 'storages.no_results' |
||||
end |
||||
|
||||
def headers |
||||
[ |
||||
['name', { caption: Storages::Storage.human_attribute_name(:name) }], |
||||
['provider_type', { caption: I18n.t('storages.provider_types.label') }], |
||||
['creator', { caption: I18n.t('storages.label_creator') }], |
||||
['created_at', { caption: Storages::ProjectStorage.human_attribute_name(:created_at) }] |
||||
] |
||||
end |
||||
|
||||
end |
||||
end |
@ -1,5 +1,5 @@ |
||||
module Storages |
||||
class RowCell < ::RowCell |
||||
class StoragesRowCell < ::RowCell |
||||
include ::IconsHelper |
||||
include ::AvatarHelper |
||||
include ::Redmine::I18n |
@ -1,6 +1,13 @@ |
||||
module Storages |
||||
class TableCell < ::TableCell |
||||
class StoragesTableCell < ::TableCell |
||||
include ::IconsHelper |
||||
|
||||
class << self |
||||
def row_class |
||||
::Storages::StoragesRowCell |
||||
end |
||||
end |
||||
|
||||
columns :name, :provider_type, :creator, :created_at |
||||
|
||||
def initial_sort |
@ -0,0 +1,88 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See COPYRIGHT and LICENSE files for more details. |
||||
#++ |
||||
|
||||
class Storages::Admin::ProjectsStoragesController < ApplicationController |
||||
layout 'admin' |
||||
before_action :find_optional_project |
||||
before_action :authorize |
||||
|
||||
menu_item :settings_projects_storages |
||||
|
||||
|
||||
def index |
||||
@projects_storages = Storages::ProjectStorage.where(project: @project).includes(:storage) |
||||
|
||||
render '/storages/project_settings/index' |
||||
end |
||||
|
||||
def new |
||||
@project_storage = Storages::ProjectStorage.new(project: @project) |
||||
@available_storages = Storages::Storage.where.not(storage_id: @project.projects_storages.pluck(:storage_id)) |
||||
|
||||
render '/storages/project_settings/new' |
||||
end |
||||
|
||||
def create |
||||
combined_params = permitted_project_storage_params |
||||
.to_h |
||||
.reverse_merge(creator_id: User.current.id, project_id: @project.id) |
||||
|
||||
@project_storage = Storages::ProjectStorage.create combined_params |
||||
|
||||
redirect_to project_settings_projects_storages_path |
||||
end |
||||
|
||||
def destroy |
||||
@project_storage = Storages::ProjectStorage.find(params[:id]) |
||||
@project_storage.destroy |
||||
|
||||
redirect_to project_settings_projects_storages_path |
||||
end |
||||
|
||||
def default_breadcrumb |
||||
# t(:project_module_storages) |
||||
end |
||||
|
||||
def show_local_breadcrumb |
||||
true |
||||
end |
||||
|
||||
current_menu_item :index do |
||||
:settings_projects_storages |
||||
end |
||||
|
||||
private |
||||
|
||||
def permitted_project_storage_params |
||||
params |
||||
.require(:storages_project_storage) |
||||
.permit('storage_id') |
||||
end |
||||
end |
@ -0,0 +1,45 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See COPYRIGHT and LICENSE files for more details. |
||||
#++ |
||||
|
||||
class Storages::Projects::SettingsController < Projects::SettingsController |
||||
menu_item :project_settings_storages |
||||
|
||||
def index |
||||
# tbd |
||||
end |
||||
|
||||
def create |
||||
# tbd |
||||
end |
||||
|
||||
def delete |
||||
# tbd |
||||
end |
||||
end |
@ -0,0 +1,38 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See COPYRIGHT and LICENSE files for more details. |
||||
#++ |
||||
|
||||
class Storages::ProjectStorage < ApplicationRecord |
||||
self.table_name = 'projects_storages' |
||||
belongs_to :project, class_name: 'Project' |
||||
belongs_to :storage, class_name: 'Storages::Storage' |
||||
belongs_to :creator, class_name: 'User' |
||||
|
||||
validates :project, uniqueness: { scope: :storage } |
||||
end |
@ -0,0 +1,15 @@ |
||||
<% html_title t(:label_administration), t("project_module_storages") %> |
||||
|
||||
<%= toolbar title: t("project_module_storages") do %> |
||||
<li class="toolbar-item"> |
||||
<%= link_to new_project_settings_projects_storage_path, |
||||
{ class: 'button -alt-highlight', |
||||
aria: { label: t(:'storages.label_new_storage') }, |
||||
title: t(:'ifc_models.label_new_storage') } do %> |
||||
<%= op_icon('button--icon icon-add') %> |
||||
<span class="button--text"><%= ::Storages::Storage.model_name.human %></span> |
||||
<% end %> |
||||
</li> |
||||
<% end %> |
||||
|
||||
<%= rails_cell ::Storages::ProjectsStoragesTableCell, @projects_storages %> |
@ -0,0 +1,18 @@ |
||||
<% html_title t(:label_administration), t("project_module_storages") %> |
||||
<% local_assigns[:additional_breadcrumb] = t('storages.label_new_storage') %> |
||||
<%= toolbar title: t("storages.label_new_storage") %> |
||||
|
||||
<%= labelled_tabular_form_for @project_storage, url: project_settings_projects_storages_path do |f| -%> |
||||
<%= error_messages_for_contract @project_storage, @errors %> |
||||
|
||||
<section class="form--section"> |
||||
<div class="form--field -required"> |
||||
<%= f.select :storage_id, |
||||
@available_storages.map { |storage| ["#{storage.name} (#{storage.provider_type})", storage.id] }, |
||||
selected: @available_storages.first.id, |
||||
container_class: '-slim' %> |
||||
</div> |
||||
</section> |
||||
|
||||
<%= styled_button_tag t(:button_create), class: "-highlight -with-icon icon-checkmark" %> |
||||
<% end %> |
Loading…
Reference in new issue