Merge pull request #1047 from ZmagoD/zd_SCI_2139_2121

adds libraries/repositories to sidebar navigation and blank page for no libraries/repositories
This commit is contained in:
Zmago Devetak 2018-04-04 13:58:24 +02:00 committed by GitHub
commit c71a8a7506
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 232 additions and 158 deletions

View file

@ -12,6 +12,7 @@
//= require jquery-ui/widgets/draggable
//= require jquery-ui/widgets/droppable
//= require jquery.ui.touch-punch.min
//= require jquery-ui/effects/effect-slide
//= require jquery.caret.min
//= require jquery.atwho.min
//= require hammer

View file

@ -6,78 +6,8 @@
animateSpinner();
location.reload();
}
function initImportRecordsModal() {
$('#importRecordsButton').off().on('click', function() {
$('#modal-import-records').modal('show');
_initParseRecordsModal();
});
}
function _initParseRecordsModal() {
$('#form-records-file').on('ajax:success', function(ev, data) {
$('#modal-import-records').modal('hide');
$(data.html).appendTo('body').promise().done(function() {
$('#parse-records-modal')
.modal('show')
.on('hidden.bs.modal', function() {
animateSpinner();
location.reload();
});
repositoryRecordsImporter();
});
}).on('ajax:error', function(ev, data) {
$(this).find('.form-group').addClass('has-error');
$(this).find('.form-group').find('.help-block').remove();
$(this).find('.form-group').append("<span class='help-block'>" +
data.responseJSON.message + '</span>');
});
}
function loadRepositoryTab() {
var param;
$('#repository-tabs a').on("click", function(e) {
e.preventDefault();
var pane = $(this);
$.ajax({
url: $(this).attr("data-url"),
type: "GET",
dataType: "json",
success: function (data) {
var tabBody = $(pane.context.hash).find(".tab-content-body");
tabBody.html(data.html);
pane.tab('show').promise().done(function(el) {
initImportRecordsModal();
RepositoryDatatable.destroy()
RepositoryDatatable.init(el.attr('data-repo-table'));
});
},
error: function (error) {
// TODO
}
});
});
// on page load
if( param = getParam('repository') ){
// load selected tab
$('a[href="#custom_repo_'+param+'"]').click();
}
else {
// load first tab content
$('#repository-tabs a:first').click();
}
// clean tab content
$('a[data-toggle="tab"]').on('hide.bs.tab', function (e) {
$(".tab-content-body").html("");
})
}
$('.create-repository').initializeModal('#create-repo-modal');
$(document).ready(function() {
loadRepositoryTab();
initImportRecordsModal();
$('#create-new-repository').initializeModal('#create-repo-modal');
});
})(window);

View file

@ -0,0 +1,38 @@
(function() {
'use strict';
function initImportRecordsModal() {
$('#importRecordsButton').off().on('click', function() {
$('#modal-import-records').modal('show');
_initParseRecordsModal();
});
}
function _initParseRecordsModal() {
$('#form-records-file').on('ajax:success', function(ev, data) {
$('#modal-import-records').modal('hide');
$(data.html).appendTo('body').promise().done(function() {
$('#parse-records-modal')
.modal('show')
.on('hidden.bs.modal', function() {
animateSpinner();
location.reload();
});
repositoryRecordsImporter();
});
}).on('ajax:error', function(ev, data) {
$(this).find('.form-group').addClass('has-error');
$(this).find('.form-group').find('.help-block').remove();
$(this).find('.form-group').append("<span class='help-block'>" +
data.responseJSON.message + '</span>');
});
}
function initialzerRepositoryTable() {
initImportRecordsModal();
RepositoryDatatable.destroy();
RepositoryDatatable.init('#' + $('.repository-table table').attr('id'));
}
$(document).ready(initialzerRepositoryTable);
})()

View file

@ -0,0 +1,35 @@
(function(global) {
'use strict';
global.SideBarToggle = (function() {
function show() {
$('#sideBarLeft').show();
$('#sideBarRight').hide();
$('#sidebar-wrapper').show(
'slide', { direction: 'right', easing: 'linear' }, 400
);
$('#wrapper').css('paddingLeft', '280px');
$('.navbar-secondary').css(
{ 'margin-left': '-280px', 'padding-left': '280px' }
);
}
function hide() {
$('#sideBarLeft').hide();
$('#sideBarRight').show();
$('#sidebar-wrapper').hide(
'slide', { direction: 'left', easing: 'linear'}, 400
);
$('#wrapper').css('paddingLeft', '0');
$('.navbar-secondary').css({
'margin-left': '0',
'padding-left': '0'
});
}
return Object.freeze({
show: show,
hide: hide
})
})();
})(window);

View file

@ -0,0 +1,8 @@
#repository-columns-dropdown {
float: right;
}
.new-repository-button {
float: left;
margin-right: 5px;
}

View file

@ -1,7 +1,7 @@
@import 'constants';
@import "mixins";
@import "main_navigation";
@import "repositories";
/** Layout **/
body,

View file

@ -11,21 +11,16 @@ class RepositoriesController < ApplicationController
before_action :check_create_permissions, only:
%i(create_new_modal create copy_modal copy)
layout 'fluid'
def index
render('repositories/index')
unless @repositories.length.zero? && current_team
redirect_to repository_path(@repositories.first) and return
end
render 'repositories/index'
end
def show_tab
respond_to do |format|
format.json do
render json: {
html: render_to_string(
partial: 'repositories/repository.html.erb',
locals: { repository: @repository }
)
}
end
end
def show
end
def create_modal
@ -53,7 +48,7 @@ class RepositoriesController < ApplicationController
if @repository.save
flash[:success] = t('repositories.index.modal_create.success_flash',
name: @repository.name)
render json: { url: team_repositories_path(repository: @repository) },
render json: { url: repository_path(@repository) },
status: :ok
else
render json: @repository.errors,
@ -287,7 +282,7 @@ class RepositoriesController < ApplicationController
end
def load_parent_vars
@team = Team.find_by_id(params[:team_id])
@team = current_team
render_404 unless @team
@repositories = @team.repositories.order(created_at: :asc)
end

View file

@ -0,0 +1,34 @@
<%= content_for :sidebar do %>
<div id="slide-panel" class="visible">
<div class="tree">
<ul>
<li>
<span class="tree-link line-wrap no-indent">
<strong title="<%= t('libraries.sidebar.title') %>"><%= t('libraries.sidebar.title') %></strong>
</span>
</li>
<% repositories.each do |repository| %>
<% cache repository do %>
<li class="<%= 'active parent_li' if current_page?(repository_path(repository)) %>" >
<span class="tree-link line-wrap no-indent">
<% if current_page?(repository_path(repository)) %>
<span title="<%= repository.name %>"><%= repository.name %></span>
<% else %>
<%= link_to repository.name,
repository_path(repository),
data: { 'no-turbolink' => 'true' } %>
<% end %>
</span>
</li>
<% end %>
<% end %>
</ul>
</div>
</div>
<% end %>
<script>
$(document).ready(function() {
$('#wrapper').show();
})
</script>

View file

@ -1,51 +1,21 @@
<% provide(:head_title, t("repositories.index.head_title")) %>
<% provide(:head_title, t("libraries.index.head_title")) %>
<% if current_team %>
<%= render partial: "repositories/breadcrumbs.html.erb",
locals: { teams: @teams, current_team: current_team, type: @type } %>
<!-- Nav tabs -->
<ul class="nav nav-tabs nav-settings" role="tablist" id="repository-tabs">
<% @repositories.each do |repo| %>
<li role="presentation">
<a href="#custom_repo_<%= repo.id %>"
data-toggle="tab"
data-repo-table="#repository-table-<%= repo.id %>"
aria-controls="custom_repo_<%= repo.id %>"
data-url="<%=team_repository_show_tab_path(current_team, repo)%>"
title="<%=repo.name%>"><%= truncate(repo.name, length: Constants::NAME_TRUNCATION_LENGTH) %></a>
</li>
<% end %>
<!-- Add new repository tab -->
<li role="presentation"
<% unless can_create_repositories?(current_team) || current_team.repositories.count < Constants::REPOSITORIES_LIMIT %>
class="disabled"
<% end %>>
<a
<% if can_create_repositories?(current_team) && current_team.repositories.count < Constants::REPOSITORIES_LIMIT %>
href="<%= create_modal_team_repositories_path %>"
class='create-repository'
data-remote='true'
<% end %>>
<span class="glyphicon glyphicon-plus"></span>
<span class="hidden-xs">&nbsp;<%= t('repositories.index.add_new_repository_tab') %></span>
</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<% @repositories.each do |repo| %>
<div class="tab-pane tab-pane-settings" id="custom_repo_<%= repo.id %>">
<!-- Tab Content -->
<div class="container-fluid">
<div class="tab-content-body"></div>
</div>
</div>
<% end %>
<%= render partial: "sidebar", locals: { repositories: @repositories } %>
<%
# show only if no repositories present. If the team will have them we will
# handle this in left side navigation bar
%>
<div class="jumbotron text-center" style="margin-top:25%">
<strong><%=t 'libraries.index.no_libraries.text' %></strong>
<h2><strong><%=t 'libraries.index.no_libraries.title' %><strong></h2>
<br />
<%= link_to t('libraries.index.no_libraries.create_new_button'),
create_modal_team_repositories_path(current_team),
class: "btn btn-primary btn-lg",
id: "create-new-repository",
remote: true %>
</div>
<% else %>
<!-- If member of no teams -->
<div class="jumbotron">
@ -54,6 +24,4 @@
</div>
<% end %>
<%= stylesheet_link_tag 'datatables' %>
<%= javascript_include_tag 'repositories/repository_datatable' %>
<%= javascript_include_tag "repositories/index", "data-turbolinks-track" => true %>

View file

@ -1,13 +1,12 @@
<%= render partial: "repositories/delete_record_modal.html.erb" %>
<%= render partial: "repositories/delete_column_modal.html.erb" %>
<%= render partial: 'repositories/export_repository_modal.html.erb',
locals: { repository: repository } %>
<% provide(:head_title, t("libraries.show.head_title", library: @repository.name)) %>
<%= stylesheet_link_tag 'datatables' %>
<%= render partial: "sidebar", locals: { repositories: @repositories } %>
<div id="alert-container"></div>
<div id="repository-toolbar">
<% if can_create_repository_rows?(repository.team) %>
<% if can_create_repository_rows?(@repository.team) %>
<button type="button" class="btn btn-default editAdd" id="addRepositoryRecord" onclick="onClickAddRecord()">
<span class="glyphicon glyphicon-plus"></span>
<span class="hidden-xs"><%= t("repositories.add_new_record") %></span>
@ -18,7 +17,7 @@
</button>
<% end %>
<% if can_read_team?(repository.team) %>
<% if can_read_team?(@repository.team) %>
<a href="#" class="btn btn-default" id="exportRepositoriesButton" data-turbolinks="false">
<span class="glyphicon glyphicon-cloud-download"></span>
<span class="hidden-xs"><%= t("my_modules.repository.export") %></span>
@ -32,36 +31,36 @@
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="true"
<%= "disabled='disabled'" unless can_manage_repository?(repository) || can_create_repositories?(repository.team) %>>
<%= "disabled" unless can_manage_repository?(@repository) || can_create_repositories?(@repository.team) %>>
<span class="glyphicon glyphicon-cog"></span>
<span class="caret"></span>
</div>
<% if can_manage_repository?(repository) || can_create_repositories?(repository.team) %>
<% if can_manage_repository?(@repository) || can_create_repositories?(@repository.team) %>
<ul class="dropdown-menu pull-right">
<li class="dropdown-header">
<%= t("repositories.index.options_dropdown.header") %>
</li>
<% if can_manage_repository?(repository) %>
<% if can_manage_repository?(@repository) %>
<li>
<%= link_to t('repositories.index.options_dropdown.rename'),
team_repository_rename_modal_path(repository_id: repository),
team_repository_rename_modal_path(current_team, repository_id: @repository),
class: "rename-repo-option",
remote: true %>
</li>
<% end %>
<% if can_create_repositories?(repository.team) %>
<% if can_create_repositories?(@repository.team) %>
<li>
<%= link_to t('repositories.index.options_dropdown.copy'),
team_repository_copy_modal_path(repository_id: repository),
team_repository_copy_modal_path(current_team, repository_id: @repository),
class: "copy-repo-option",
remote: true %>
</li>
<% end %>
<% if can_manage_repository?(repository) %>
<% if can_manage_repository?(@repository) %>
<li role="separator" class="divider"></li>
<li>
<%= link_to t('repositories.index.modal_delete.delete'),
team_repository_destroy_modal_path(repository_id: repository),
team_repository_destroy_modal_path(current_team, repository_id: @repository),
class: "delete-repo-option",
remote: true %>
</li>
@ -71,8 +70,40 @@
</div>
</div>
<div id="datatables-buttons" style="display: inline;">
<%= render partial: "columns_reorder_dropdown", formats: :html %>
<div class="new-repository-button">
<% if can_create_repositories?(@repository.team) %>
<%= link_to t('libraries.index.no_libraries.create_new_button'),
create_modal_team_repositories_path(@repository.team),
class: "btn btn-default",
id: "create-new-repository",
remote: true %>
<% end %>
</div>
<div id="repository-columns-dropdown" class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">
<%= t('repositories.columns') %>
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right smart-dropdown" id="repository-columns-list">
<% if can_create_repository_columns?(@repository.team) %>
<li class="add-new-column-form">
<div id="new-column-form" class="form-group" data-action="<%= repository_repository_columns_path(@repository) %>">
<div class="input-group">
<input class="form-control" id="new-column-name" placeholder="<%= t("repositories.column_new_text") %>">
<span class="input-group-btn">
<a id="add-new-column-button" class="btn btn-primary">
<%= t("repositories.column_create") %>
</a>
</span>
</div>
</div>
</li>
<% end %>
</ul>
</div>
</div>
</div>
@ -94,7 +125,7 @@
<span class="hidden-xs-custom"><%= t("repositories.edit_record") %></span>
</button>
<% if can_manage_repository_rows?(repository.team) %>
<% if can_manage_repository_rows?(@repository.team) %>
<button type="button" class="btn btn-default"
id="deleteRepositoryRecordsButton" data-target="#deleteRepositoryRecord" data-toggle="modal" disabled>
<span class="glyphicon glyphicon-trash"></span>
@ -107,10 +138,19 @@
<%= render partial: "repositories/repository_table.html.erb",
locals: {
repository: repository,
repository_index_link: repository_table_index_path(repository)
repository: @repository,
repository_index_link: repository_table_index_path(@repository)
}
%>
<%= render partial: 'repositories/import_repository_records_modal.html.erb',
locals: { repository: repository } %>
locals: { repository: @repository } %>
<%= render partial: "repositories/delete_record_modal.html.erb" %>
<%= render partial: "repositories/delete_column_modal.html.erb" %>
<%= render partial: 'repositories/export_repository_modal.html.erb',
locals: { repository: @repository } %>
<%= javascript_include_tag 'repositories/edit', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'repositories/repository_datatable' %>
<%= javascript_include_tag "repositories/show", "data-turbolinks-track" => true %>
<%= javascript_include_tag "repositories/index", "data-turbolinks-track" => true %>

View file

@ -1,13 +1,26 @@
<div id="left-menu-bar" class="menu-bar">
<ul class="nav">
<li class="text-center">
<span id="sideBarLeft"
class="glyphicon glyphicon-chevron-left"
aria-hidden="true"
onclick="SideBarToggle.hide()"
></span>
<span id="sideBarRight"
class="glyphicon glyphicon-chevron-right"
aria-hidden="true"
onclick="SideBarToggle.show()"
style="display:none;"
></span>
</li>
<li class="<%= "active" if projects_are_selected? %>">
<%= link_to projects_path, id: "projects-link", class: "toggle-sidebar-link", title: t('left_menu_bar.projects') do %>
<%= link_to projects_path, id: "projects-link", title: t('left_menu_bar.projects') do %>
<span class="glyphicon glyphicon-home"></span>
<span><%= t('left_menu_bar.projects') %></span>
<% end %>
</li>
<li class="<%= "active" if repositories_are_selected? %>">
<%= link_to team_repositories_path(current_team), id: "repositories-link", title: t('left_menu_bar.repositories') do %>
<%= link_to repositories_path, id: "repositories-link", title: t('left_menu_bar.repositories') do %>
<span class="fa fa-cubes" aria-hidden="true"></span>
<span><%= t('left_menu_bar.repositories') %></span>
<% end %>
@ -65,3 +78,5 @@
</li>
</ul>
</div>
<%= javascript_include_tag("sidebar_toggle") %>

View file

@ -1,6 +1,5 @@
<%= content_for :sidebar do %>
<div id="slide-panel" class="visible">
<div class="tree">
<ul>
<% if project_page? && action_name == 'index' ||

View file

@ -83,6 +83,8 @@ Rails.application.config.assets.precompile +=
Rails.application.config.assets.precompile +=
%w(repositories/my_module_repository.js)
Rails.application.config.assets.precompile += %w(activities/index.js)
Rails.application.config.assets.precompile += %w(repositories/show.js)
Rails.application.config.assets.precompile += %w(sidebar_toggle.js)
# Libraries needed for Handsontable formulas
Rails.application.config.assets.precompile += %w(lodash.js)

View file

@ -990,6 +990,17 @@ en:
no_records_unassigned_flash: "No items were unassigned from task"
default_column: 'Name'
libraries:
sidebar:
title: "Inventories"
index:
head_title: "Inventories"
no_libraries:
text: "You don't have any inventories."
title: "Please create your first Inventory"
create_new_button: "Create New Inventory"
show:
head_title: "Inventories | %{library}"
repository_row:
modal_info:
head_title: "Information for item '%{repository_row}'"

View file

@ -153,8 +153,6 @@ Rails.application.routes.draw do
get 'create_modal', to: 'repositories#create_modal',
defaults: { format: 'json' }
end
get 'show_tab', to: 'repositories#show_tab',
defaults: { format: 'json' }
get 'destroy_modal', to: 'repositories#destroy_modal',
defaults: { format: 'json' }
get 'rename_modal', to: 'repositories#rename_modal',