#388: Updated UI
This commit is contained in:
parent
ac473294b7
commit
ea62617ed5
|
@ -1,54 +1,65 @@
|
|||
RosaABF.controller 'ContentsController', ['$scope', '$http', ($scope, $http) ->
|
||||
RosaABF.controller 'ContentsController', ['$scope', '$http', '$location', ($scope, $http, $location) ->
|
||||
|
||||
$scope.platform = null
|
||||
$scope.path = null
|
||||
$scope.platform = $('#platform_name').val()
|
||||
$scope.processing = true
|
||||
$scope.contents = []
|
||||
$scope.folders = []
|
||||
|
||||
$scope.init = (platform, path)->
|
||||
$scope.platform = platform
|
||||
$scope.path = path
|
||||
$scope.platform_path = Routes.platform_contents_path($scope.platform)
|
||||
$scope.refresh()
|
||||
# Fixes: redirect to page after form submit
|
||||
$("#search_contents_form").on 'submit', ->
|
||||
false
|
||||
|
||||
$scope.refresh = (path) ->
|
||||
$scope.refresh = ->
|
||||
$scope.processing = true
|
||||
path = $scope.path unless path
|
||||
|
||||
params =
|
||||
platform_id: $scope.platform
|
||||
path: path
|
||||
path: $('#path').val()
|
||||
term: $('#term').val()
|
||||
format: 'json'
|
||||
|
||||
$http.get(Routes.platform_contents_path(params)).success( (data) ->
|
||||
$scope.folders = data.folders
|
||||
$scope.contents = data.contents
|
||||
$scope.path = data.path
|
||||
$scope.back = data.back
|
||||
$scope.processing = false
|
||||
).error( ->
|
||||
$scope.contents = []
|
||||
$scope.processing = false
|
||||
)
|
||||
true
|
||||
|
||||
$scope.open = (content) ->
|
||||
if content.is_folder
|
||||
$scope.refresh(content.path)
|
||||
return if $scope.processing
|
||||
if $.type(content) == 'string'
|
||||
$location.search('path', content)
|
||||
else if content.is_folder
|
||||
$location.search('path', content.subpath)
|
||||
|
||||
$scope.destroy = (content) ->
|
||||
params =
|
||||
platform_id: $scope.platform
|
||||
path: content.path
|
||||
path: content.subpath
|
||||
format: 'json'
|
||||
|
||||
content.processing = true
|
||||
$http.delete(Routes.platform_content_path(params)).success( ->
|
||||
$http.delete(Routes.remove_file_platform_contents_path($scope.platform, params)).success( ->
|
||||
$scope.refresh()
|
||||
).error( ->
|
||||
$scope.refresh()
|
||||
)
|
||||
true
|
||||
|
||||
# $http.delete(
|
||||
# Routes.project_path($scope.name_with_owner),
|
||||
# {file: {autostart_status: $scope.autostart_status}, format: 'json'}
|
||||
# );
|
||||
$scope.search = ->
|
||||
$location.search('term', $('#term').val())
|
||||
false
|
||||
|
||||
$scope.$on '$locationChangeSuccess', (event) ->
|
||||
$scope.updateParams()
|
||||
$scope.refresh()
|
||||
|
||||
$scope.updateParams = ->
|
||||
params = $location.search()
|
||||
$('#path').val(params['path'])
|
||||
$('#term').val(params['term'])
|
||||
|
||||
]
|
|
@ -2,6 +2,7 @@
|
|||
@import "design/main";
|
||||
@import "design/git";
|
||||
@import "design/common";
|
||||
@import "design/contents";
|
||||
@import "design/custom";
|
||||
@import "design/build_lists_monitoring";
|
||||
@import "design/profile";
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#contents {
|
||||
|
||||
a {
|
||||
cursor: pointer;
|
||||
}
|
||||
.path {
|
||||
a {
|
||||
margin-right: 20px;
|
||||
}
|
||||
.text {
|
||||
padding: 5px 10px;
|
||||
background-color: #dcecfa;
|
||||
float: left;
|
||||
height: 14px;
|
||||
}
|
||||
.arrow-right {
|
||||
content: '';
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: 12px solid transparent;
|
||||
border-left: 12px solid #dcecfa;
|
||||
float: left;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2047,29 +2047,6 @@ article .activity .top {
|
|||
margin: 2px 0;
|
||||
}
|
||||
|
||||
#contents {
|
||||
.path {
|
||||
a {
|
||||
margin-right: 20px;
|
||||
}
|
||||
.text {
|
||||
padding: 5px 10px;
|
||||
background-color: #dcecfa;
|
||||
float: left;
|
||||
height: 14px;
|
||||
}
|
||||
.arrow-right {
|
||||
content: '';
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: 12px solid transparent;
|
||||
border-left: 12px solid #dcecfa;
|
||||
float: left;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
table tbody {
|
||||
td.build-list-statuses {
|
||||
background: #FFF;
|
||||
|
|
|
@ -2,17 +2,17 @@ class Platforms::ContentsController < Platforms::BaseController
|
|||
include PaginateHelper
|
||||
|
||||
before_filter :authenticate_user!
|
||||
skip_before_filter :authenticate_user! if APP_CONFIG['anonymous_access']
|
||||
skip_before_filter :authenticate_user!, only: :index if APP_CONFIG['anonymous_access']
|
||||
|
||||
load_and_authorize_resource :platform
|
||||
|
||||
def index
|
||||
@path = params[:path].to_s
|
||||
@term = params[:term]
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json do
|
||||
@path = params[:path].to_s
|
||||
@term = params[:term]
|
||||
@contents = PlatformContent.find_by_platform(@platform, @path, @term)
|
||||
.paginate(paginate_params)
|
||||
end
|
||||
|
@ -20,8 +20,9 @@ class Platforms::ContentsController < Platforms::BaseController
|
|||
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
def remove_file
|
||||
PlatformContent.remove_file(@platform, params[:path])
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
module ContentsHelper
|
||||
|
||||
def build_content_paths(platform, path)
|
||||
paths = ['/']
|
||||
paths |= path.split('/').select(&:present?)
|
||||
paths.uniq!
|
||||
|
||||
compound_path = ''
|
||||
paths.map do |p|
|
||||
compound_path << p << '/' if p != '/'
|
||||
link_to(platform_content_path(platform, compound_path), {remote: true}) do
|
||||
content_tag(:span, p, {class: 'text'}) +
|
||||
content_tag(:span, '', {class: 'arrow-right'})
|
||||
end
|
||||
end.join.html_safe
|
||||
end
|
||||
|
||||
def platform_content_path(platform, path, name = nil)
|
||||
full_path = platform_contents_path(platform)
|
||||
full_path << '/' << path if path.present?
|
||||
full_path << ('/' << name) if name.present?
|
||||
full_path
|
||||
end
|
||||
|
||||
end
|
|
@ -114,7 +114,7 @@ class Ability
|
|||
can [:read, :related, :members], Platform, owner_type: 'Group', owner_id: user_group_ids
|
||||
can([:read, :related, :members], Platform, read_relations_for('platforms')) {|platform| local_reader? platform}
|
||||
can [:read, :related], Platform, id: user.repositories.pluck(:platform_id)
|
||||
can([:update, :destroy, :change_visibility], Platform) {|platform| owner?(platform) }
|
||||
can([:update, :destroy, :change_visibility, :remove_file], Platform) {|platform| owner?(platform) }
|
||||
can([:local_admin_manage, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) }
|
||||
|
||||
can([:create, :publish], MassBuild) {|mass_build| owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)}
|
||||
|
|
|
@ -61,14 +61,7 @@ class PlatformContent
|
|||
term = (term || '').strip.gsub(/[\\\/]+/, '')
|
||||
.gsub(/[^\w\-\+\.]/, '_')
|
||||
|
||||
path = path.split(File::SEPARATOR).map(&:strip).select(&:present?)
|
||||
.map{ |p|
|
||||
# Strip out the non-ascii character
|
||||
p.gsub(/[\\\/]+/, '')
|
||||
.gsub(/^[\.]+/, '')
|
||||
.gsub(/[^\w\-\.]/, '_')
|
||||
}
|
||||
.join(File::SEPARATOR)
|
||||
path = sanitize_path(path)
|
||||
results = Dir.glob(File.join(platform.path, path, "*#{term}*"))
|
||||
if term
|
||||
results = results.sort_by(&:length)
|
||||
|
@ -78,4 +71,19 @@ class PlatformContent
|
|||
results.map{ |p| PlatformContent.new(platform, p) }
|
||||
end
|
||||
|
||||
def self.remove_file(platform, path)
|
||||
path = File.join(platform.path, sanitize_path(path))
|
||||
FileUtils.rm_f(path) if File.exist?(path)
|
||||
end
|
||||
|
||||
def self.sanitize_path(path)
|
||||
path.split(File::SEPARATOR).map(&:strip).select(&:present?)
|
||||
.map{ |p|
|
||||
# Strip out the non-ascii character
|
||||
p.gsub(/[\\\/]+/, '')
|
||||
.gsub(/^[\.]+/, '')
|
||||
.gsub(/[^\w\-\.]/, '_')
|
||||
}.join(File::SEPARATOR)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,43 +0,0 @@
|
|||
#contents
|
||||
|
||||
= form_for @platform, url: platform_content_path(@platform, @path), html: { class: :form, remote: true, method: :get } do |f|
|
||||
= tracker_search_field(:term, @term.present? ? @term : t('layout.platforms.search_contents'))
|
||||
= f.submit t('layout.search.header'), data: {'disable-with' => t('layout.processing')}
|
||||
%br
|
||||
|
||||
.path= build_content_paths(@platform, @path)
|
||||
.both
|
||||
|
||||
- can_delete = can? :update, @platform
|
||||
%table.tablesorter.project{cellpadding: 0, cellspacing: 0 }
|
||||
%tbody
|
||||
|
||||
- if @path.present?
|
||||
%tr
|
||||
%td= link_to '../', platform_content_path(@platform, @path, '../'), {remote: true}
|
||||
%td
|
||||
%td
|
||||
- if can_delete
|
||||
%td
|
||||
|
||||
- (@contents.select(&:is_folder?) | @contents).each do |content|
|
||||
%tr
|
||||
%td
|
||||
- options = {class: 'files-see'}
|
||||
- if content.is_folder?
|
||||
- pic = 'folder.png'
|
||||
- path = platform_content_path(@platform, @path, content.name)
|
||||
- options[:remote] = true
|
||||
.pic= image_tag pic || 'code.png'
|
||||
.name= link_to(content.name, path || content.download_url, options)
|
||||
%td= link_to t('activerecord.models.build_list'), content.build_list if content.build_list
|
||||
%td= number_to_human_size(content.size) unless content.is_folder?
|
||||
- if can_delete && !content.is_folder?
|
||||
%td.buttons
|
||||
/= link_to "sss", method: :delete, data: { confirm: t('layout.confirm') } do
|
||||
%span.delete{ 'ng-click' => "destroy('#{content.subpath}')" }
|
||||
- else
|
||||
%td
|
||||
.both
|
||||
|
||||
= will_paginate @contents, {remote: true}
|
|
@ -6,49 +6,52 @@
|
|||
= t('layout.platforms.contents_of')
|
||||
= @platform.name
|
||||
|
||||
/ = render 'contents'
|
||||
/ #contents-container{ 'ng-controller' => 'ContentsController', 'ng-init' => "platform = '#{@platform.name}'" }
|
||||
#contents{ 'ng-controller' => 'ContentsController' }
|
||||
|
||||
#contents{ 'ng-controller' => 'ContentsController', 'ng-init' => "init('#{@platform.name}', '#{@path}')" }
|
||||
|
||||
= form_for @platform, html: { class: :form, 'ng-submit' => 'refresh(path)' } do |f|
|
||||
/ = tracker_search_field(:term, @term.present? ? @term : t('layout.platforms.search_contents'))
|
||||
%input#term{ name: 'term', type: 'text', value: @term, placeholder: t('layout.platforms.search_contents') }
|
||||
= form_for @platform, html: { class: :form, 'ng-submit' => 'search()', id: 'search_contents_form' } do |f|
|
||||
= f.hidden_field :name
|
||||
= hidden_field_tag 'path'
|
||||
%input#term{ name: 'term', type: 'text', placeholder: t('layout.platforms.search_contents') }
|
||||
= f.submit t('layout.search.header'), data: {'disable-with' => t('layout.processing')}
|
||||
%br
|
||||
|
||||
|
||||
|
||||
.path= build_content_paths(@platform, @path)
|
||||
.path
|
||||
%a{ 'ng-repeat' => 'folder in folders' }
|
||||
%span.text{ 'ng-click' => "open(folder.path)" } {{folder.name}}
|
||||
%span.arrow-right
|
||||
.both
|
||||
|
||||
- can_delete = can? :update, @platform
|
||||
- can_remove = can? :remove_file, @platform
|
||||
%table.tablesorter.project{cellpadding: 0, cellspacing: 0, 'ng-hide' => 'processing' }
|
||||
%tbody
|
||||
|
||||
%tr{ 'ng-show' => 'path' }
|
||||
%tr{ 'ng-show' => 'back' }
|
||||
%td
|
||||
%a{'ng-href' => '{{path}}', 'ng-click' => "open(content)" } ../
|
||||
%a{ 'ng-click' => "open(back)" } ../
|
||||
%td
|
||||
%td
|
||||
- if can_delete
|
||||
- if can_remove
|
||||
%td
|
||||
|
||||
%tr{'ng-repeat' => 'content in contents'}
|
||||
%td
|
||||
.pic{ 'ng-show' => 'content.is_folder' }= image_tag 'folder.png'
|
||||
.pic{ 'ng-hide' => 'content.is_folder' }= image_tag 'code.png'
|
||||
%td{ 'ng-show' => 'content.is_folder' }
|
||||
.pic= image_tag 'folder.png'
|
||||
.name
|
||||
%a.files-see{'ng-href' => '{{content.url}}', 'ng-click' => "open(content)" } {{content.name}}
|
||||
%a.files-see{ 'ng-click' => "open(content)" } {{content.name}}
|
||||
%td{ 'ng-hide' => 'content.is_folder' }
|
||||
.pic= image_tag 'code.png'
|
||||
.name
|
||||
%a.files-see{'ng-href' => '{{content.download_url}}'} {{content.name}}
|
||||
%td
|
||||
%a{'ng-href' => '{{content.build_list.url}}', 'ng-show' => 'content.build_list' }
|
||||
= t('activerecord.models.build_list')
|
||||
%td {{content.size}}
|
||||
- if can_delete
|
||||
- if can_remove
|
||||
%td{ 'ng-show' => 'content.is_folder' }
|
||||
%td.buttons{ 'ng-hide' => 'content.is_folder' }
|
||||
%div{ 'ng-show' => 'content.processing' }
|
||||
= t('layout.processing')
|
||||
%span.delete{ 'ng-click' => "destroy(content)" }
|
||||
%span.delete{ 'ng-click' => "destroy(content)", 'ng-hide' => 'content.processing' }
|
||||
.both
|
||||
|
||||
= render 'shared/angularjs_will_paginate'
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
$('#contents').html("#{escape_javascript(render 'contents')}");
|
||||
$('.pagination a').attr('data-remote', 'true');
|
|
@ -2,18 +2,22 @@ json.contents (@contents.select(&:is_folder?) | @contents) do |content|
|
|||
json.(content, :name)
|
||||
json.is_folder content.is_folder?
|
||||
|
||||
path =
|
||||
if content.is_folder?
|
||||
content.subpath
|
||||
else
|
||||
content.download_url
|
||||
end
|
||||
json.path path
|
||||
json.download_url content.download_url unless content.is_folder?
|
||||
json.subpath content.subpath
|
||||
|
||||
json.build_list do
|
||||
json.url build_list_path(content.build_list)
|
||||
end if content.build_list
|
||||
end
|
||||
|
||||
json.path @path
|
||||
paths = @path.split('/').select(&:present?)
|
||||
compound_path = ''
|
||||
json.folders (['/'] | paths) do |folder|
|
||||
compound_path << '/' << folder if folder != '/'
|
||||
json.path compound_path.dup
|
||||
json.name folder
|
||||
end
|
||||
|
||||
json.back paths.size == 1 ? '/' : paths[0...-1].join('/')
|
||||
|
||||
json.pages angularjs_will_paginate(@contents)
|
||||
|
|
|
@ -175,8 +175,11 @@ Rosa::Application.routes.draw do
|
|||
get :advisories
|
||||
end
|
||||
|
||||
resources :contents, only: %i(index destroy)
|
||||
get '/contents/*path' => 'contents#index', format: false
|
||||
resources :contents, only: %i(index) do
|
||||
collection do
|
||||
delete :remove_file
|
||||
end
|
||||
end
|
||||
|
||||
resources :mass_builds, only: [:create, :new, :index] do
|
||||
member do
|
||||
|
|
Loading…
Reference in New Issue