From ea62617ed55c4c010db7f57f3b86c1f1b8b547af Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 21 May 2014 01:15:06 +0400 Subject: [PATCH] #388: Updated UI --- .../controllers/contents_controller.coffee | 55 +++++++++++-------- app/assets/stylesheets/application.scss | 1 + app/assets/stylesheets/design/contents.scss | 26 +++++++++ app/assets/stylesheets/design/custom.scss | 23 -------- .../platforms/contents_controller.rb | 11 ++-- app/helpers/contents_helper.rb | 25 --------- app/models/ability.rb | 2 +- app/models/platform_content.rb | 24 +++++--- .../platforms/contents/_contents.html.haml | 43 --------------- app/views/platforms/contents/index.html.haml | 43 ++++++++------- app/views/platforms/contents/index.js.haml | 2 - .../platforms/contents/index.json.jbuilder | 20 ++++--- config/routes.rb | 7 ++- 13 files changed, 123 insertions(+), 159 deletions(-) create mode 100644 app/assets/stylesheets/design/contents.scss delete mode 100644 app/helpers/contents_helper.rb delete mode 100644 app/views/platforms/contents/_contents.html.haml delete mode 100644 app/views/platforms/contents/index.js.haml diff --git a/app/assets/javascripts/angularjs/controllers/contents_controller.coffee b/app/assets/javascripts/angularjs/controllers/contents_controller.coffee index 57ce51197..13dab6bdf 100644 --- a/app/assets/javascripts/angularjs/controllers/contents_controller.coffee +++ b/app/assets/javascripts/angularjs/controllers/contents_controller.coffee @@ -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 - format: 'json' + 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']) ] \ No newline at end of file diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index f54b1889b..9327f4fc5 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -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"; diff --git a/app/assets/stylesheets/design/contents.scss b/app/assets/stylesheets/design/contents.scss new file mode 100644 index 000000000..e33c9d81d --- /dev/null +++ b/app/assets/stylesheets/design/contents.scss @@ -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; + } + } + +} \ No newline at end of file diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 1305a4776..637213d62 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -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; diff --git a/app/controllers/platforms/contents_controller.rb b/app/controllers/platforms/contents_controller.rb index 4568dc0f9..4ac5e832a 100644 --- a/app/controllers/platforms/contents_controller.rb +++ b/app/controllers/platforms/contents_controller.rb @@ -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 diff --git a/app/helpers/contents_helper.rb b/app/helpers/contents_helper.rb deleted file mode 100644 index ca7c0048a..000000000 --- a/app/helpers/contents_helper.rb +++ /dev/null @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index 5ca7f4ea6..f3c01f2d5 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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)} diff --git a/app/models/platform_content.rb b/app/models/platform_content.rb index d2a3d247c..4c92dfe8d 100644 --- a/app/models/platform_content.rb +++ b/app/models/platform_content.rb @@ -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 \ No newline at end of file diff --git a/app/views/platforms/contents/_contents.html.haml b/app/views/platforms/contents/_contents.html.haml deleted file mode 100644 index ac8e64c25..000000000 --- a/app/views/platforms/contents/_contents.html.haml +++ /dev/null @@ -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} \ No newline at end of file diff --git a/app/views/platforms/contents/index.html.haml b/app/views/platforms/contents/index.html.haml index 65dd88022..4f9ecee19 100644 --- a/app/views/platforms/contents/index.html.haml +++ b/app/views/platforms/contents/index.html.haml @@ -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', 'ng-init' => "init('#{@platform.name}', '#{@path}')" } +#contents{ 'ng-controller' => 'ContentsController' } - = 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' diff --git a/app/views/platforms/contents/index.js.haml b/app/views/platforms/contents/index.js.haml deleted file mode 100644 index 2612b957a..000000000 --- a/app/views/platforms/contents/index.js.haml +++ /dev/null @@ -1,2 +0,0 @@ -$('#contents').html("#{escape_javascript(render 'contents')}"); -$('.pagination a').attr('data-remote', 'true'); \ No newline at end of file diff --git a/app/views/platforms/contents/index.json.jbuilder b/app/views/platforms/contents/index.json.jbuilder index b87d18025..d55af4938 100644 --- a/app/views/platforms/contents/index.json.jbuilder +++ b/app/views/platforms/contents/index.json.jbuilder @@ -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) diff --git a/config/routes.rb b/config/routes.rb index 3c071be7c..7ef5bdf0c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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