From ea5a9c8b054a05743b961b00bfb98430d62976d7 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 27 Oct 2014 23:14:49 +0300 Subject: [PATCH] #369: updated UI for Contents, Clone, Advisories --- .../platforms/contents_controller.js.coffee | 71 +++++++++++++++++ .../platforms/contents_controller.rb | 1 + app/helpers/application_helper.rb | 2 +- app/models/platform.rb | 5 +- app/views/platforms/contents/index.html.haml | 58 -------------- app/views/platforms/contents/index.html.slim | 79 +++++++++++++++++++ .../platforms/platforms/_advisories.html.haml | 7 -- .../platforms/platforms/_advisories.html.slim | 7 ++ .../platforms/platforms/_advisory.html.haml | 3 - .../platforms/platforms/_advisory.html.slim | 3 + .../platforms/platforms/advisories.html.haml | 7 +- app/views/platforms/platforms/clone.html.haml | 17 ---- app/views/platforms/platforms/clone.html.slim | 18 +++++ app/views/platforms/platforms/index.html.haml | 24 ------ app/views/platforms/platforms/index.html.slim | 25 ++++++ .../platforms/platforms/members.html.haml | 10 --- .../platforms/platforms/members.html.slim | 11 +++ .../shared/_angularjs_will_paginate.html.haml | 17 ---- .../shared/_angularjs_will_paginate.html.slim | 20 +++++ config/locales/models/platform.en.yml | 13 ++- config/locales/models/platform.ru.yml | 9 +++ 21 files changed, 264 insertions(+), 143 deletions(-) create mode 100644 app/assets/javascripts/angular-new/platforms/contents_controller.js.coffee delete mode 100644 app/views/platforms/contents/index.html.haml create mode 100644 app/views/platforms/contents/index.html.slim delete mode 100644 app/views/platforms/platforms/_advisories.html.haml create mode 100644 app/views/platforms/platforms/_advisories.html.slim delete mode 100644 app/views/platforms/platforms/_advisory.html.haml create mode 100644 app/views/platforms/platforms/_advisory.html.slim delete mode 100644 app/views/platforms/platforms/clone.html.haml create mode 100644 app/views/platforms/platforms/clone.html.slim delete mode 100644 app/views/platforms/platforms/index.html.haml create mode 100644 app/views/platforms/platforms/index.html.slim delete mode 100644 app/views/platforms/platforms/members.html.haml create mode 100644 app/views/platforms/platforms/members.html.slim delete mode 100644 app/views/shared/_angularjs_will_paginate.html.haml create mode 100644 app/views/shared/_angularjs_will_paginate.html.slim diff --git a/app/assets/javascripts/angular-new/platforms/contents_controller.js.coffee b/app/assets/javascripts/angular-new/platforms/contents_controller.js.coffee new file mode 100644 index 000000000..3e8454f6f --- /dev/null +++ b/app/assets/javascripts/angular-new/platforms/contents_controller.js.coffee @@ -0,0 +1,71 @@ +RosaABF.controller 'ContentsController', ['$scope', '$http', '$location', ($scope, $http, $location) -> + + $scope.platform = $('#platform_name').val() + $scope.processing = true + $scope.contents = [] + $scope.folders = [] + $scope.pages = [] + + # Fixes: redirect to page after form submit + $("#search_contents_form").on 'submit', -> + false + + $scope.refresh = -> + $scope.processing = true + + params = + platform_id: $scope.platform + path: $('#path').val() + term: $('#platform_term').val() + page: $('#page').val() + format: 'json' + + $http.get(Routes.platform_contents_path(params)).success( (data) -> + $scope.folders = data.folders + $scope.contents = data.contents + $scope.pages = data.pages + $scope.back = data.back + $scope.processing = false + ).error( -> + $scope.contents = [] + $scope.processing = false + ) + true + + $scope.open = (content) -> + 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 = + path: content.subpath + format: 'json' + + content.processing = true + $http.delete(Routes.remove_file_platform_contents_path($scope.platform, params)).success( -> + $scope.refresh() + ).error( -> + $scope.refresh() + ) + true + + $scope.search = -> + $location.search('term', $('#platform_term').val()) + + $scope.$on '$locationChangeSuccess', (event) -> + $scope.updateParams() + $scope.refresh() + + $scope.updateParams = -> + params = $location.search() + $('#path').val(params['path']) + $('#platform_term').val(params['term']) + $('#page').val(params['page']) + + $scope.goToPage = (number) -> + $location.search('page', number) + +] \ No newline at end of file diff --git a/app/controllers/platforms/contents_controller.rb b/app/controllers/platforms/contents_controller.rb index 5624000f2..963f9a0c8 100644 --- a/app/controllers/platforms/contents_controller.rb +++ b/app/controllers/platforms/contents_controller.rb @@ -1,5 +1,6 @@ class Platforms::ContentsController < Platforms::BaseController include PaginateHelper + layout 'bootstrap' before_filter :authenticate_user! skip_before_filter :authenticate_user!, only: :index if APP_CONFIG['anonymous_access'] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index eb0192ff4..96e470bab 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -57,7 +57,7 @@ module ApplicationHelper def alert_class(type) case type.to_s - when 'error' + when 'error', 'alert' 'alert-danger' when 'notice' 'alert-success' diff --git a/app/models/platform.rb b/app/models/platform.rb index 37dfe8388..fbbc7415b 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -108,9 +108,10 @@ class Platform < ActiveRecord::Base :released, :platform_arch_settings_attributes, :automatic_metadata_regeneration, - :admin_id + :admin_id, + :term - attr_accessor :admin_id + attr_accessor :admin_id, :term attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type diff --git a/app/views/platforms/contents/index.html.haml b/app/views/platforms/contents/index.html.haml deleted file mode 100644 index 7eb06f393..000000000 --- a/app/views/platforms/contents/index.html.haml +++ /dev/null @@ -1,58 +0,0 @@ -- set_meta_tags title: [title_object(@platform), t('layout.platforms.contents')] -= render 'platforms/base/submenu' -= render 'platforms/base/sidebar' - -%h3 - = t('layout.platforms.contents_of') - = @platform.name - -#contents{ 'ng-controller' => 'ContentsController' } - - = form_for @platform, html: { class: :form, 'ng-submit' => 'search()', id: 'search_contents_form' } do |f| - = f.hidden_field :name - = hidden_field_tag 'path' - = hidden_field_tag 'page' - %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 - %a{ 'ng-repeat' => 'folder in folders' } - %span.text{ 'ng-click' => "open(folder.path)" } {{folder.name}} - %span.arrow-right - .both - - - can_remove = can? :remove_file, @platform - %table.tablesorter.project{cellpadding: 0, cellspacing: 0, 'ng-hide' => 'processing' } - %tbody - - %tr{ 'ng-show' => 'back' } - %td - %a{ 'ng-click' => "open(back)" } ../ - %td - %td - - if can_remove - %td - - %tr{'ng-repeat' => 'content in contents'} - %td{ 'ng-show' => 'content.is_folder' } - .pic= image_tag 'folder.png' - .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_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)", 'ng-hide' => 'content.processing', 'ng-confirm-click' => t('layout.confirm') }   - .both - - = render 'shared/angularjs_will_paginate' diff --git a/app/views/platforms/contents/index.html.slim b/app/views/platforms/contents/index.html.slim new file mode 100644 index 000000000..e3290145a --- /dev/null +++ b/app/views/platforms/contents/index.html.slim @@ -0,0 +1,79 @@ +- set_meta_tags title: [title_object(@platform), t('layout.platforms.contents')] += render 'platforms/base/submenu' + +.container + h3 + = t('layout.platforms.contents_of') + |   + = @platform.name + + #contents ng-controller='ContentsController' + + = simple_form_for @platform, html: { 'ng-submit' => 'search()', id: 'search_contents_form' } do |f| + fieldset + = f.hidden_field :name + = hidden_field_tag 'path' + = hidden_field_tag 'page' + = f.input :term + + .button_block + button type="submit" class="btn btn-default" data-disable-with=t('layout.processing') + = t('layout.search.header') + + / input name='term' type='text' placeholder=t('layout.platforms.search_contents') + / |   + / = f.submit t('layout.search.header'), data: {'disable-with' => t('layout.processing')}, class: 'btn btn-sm btn-primary' + + / = form_for @platform, html: { class: :form, 'ng-submit' => 'search()', id: 'search_contents_form' } do |f| + / = f.hidden_field :name + / = hidden_field_tag 'path' + / = hidden_field_tag 'page' + / input name='term' type='text' placeholder=t('layout.platforms.search_contents') + / |   + / = f.submit t('layout.search.header'), data: {'disable-with' => t('layout.processing')}, class: 'btn btn-sm btn-primary' + br + + .path + a ng-repeat='folder in folders' + span.text ng-click="open(folder.path)" {{folder.name}} + span.arrow-right + .both + + - can_remove = can? :remove_file, @platform + table.table ng-show='!processing' + tbody + + tr ng-show='back' + td + a ng-click="open(back)" ../ + td + td + - if can_remove + td + + tr ng-repeat='content in contents' + td ng-show='content.is_folder' + span.glyphicon.glyphicon-folder-close + |   + span + a.files-see ng-click="open(content)" {{content.name}} + td ng-hide='content.is_folder' + span.glyphicon.glyphicon-file + |   + span + 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_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)" ng-hide='content.processing' ng-confirm-click=t('layout.confirm') + |   + .both + + = render 'shared/angularjs_will_paginate' diff --git a/app/views/platforms/platforms/_advisories.html.haml b/app/views/platforms/platforms/_advisories.html.haml deleted file mode 100644 index 74a140300..000000000 --- a/app/views/platforms/platforms/_advisories.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%table#myTable.tablesorter.advisories{cellspacing: "0", cellpadding: "0"} - %thead - %tr - %th.th1= t("activerecord.attributes.advisory.advisory_id") - %th.th2= t("activerecord.attributes.advisory.description") - %tbody - = render partial: 'advisory', collection: @advisories, as: :advisory diff --git a/app/views/platforms/platforms/_advisories.html.slim b/app/views/platforms/platforms/_advisories.html.slim new file mode 100644 index 000000000..324aa005b --- /dev/null +++ b/app/views/platforms/platforms/_advisories.html.slim @@ -0,0 +1,7 @@ +table.table.table-striped + thead + tr + th= t("activerecord.attributes.advisory.advisory_id") + th= t("activerecord.attributes.advisory.description") + tbody + = render partial: 'advisory', collection: @advisories, as: :advisory diff --git a/app/views/platforms/platforms/_advisory.html.haml b/app/views/platforms/platforms/_advisory.html.haml deleted file mode 100644 index 64884058a..000000000 --- a/app/views/platforms/platforms/_advisory.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -%tr{class: cycle("odd", "even")} - %td= link_to advisory.advisory_id, advisory_path(advisory) - %td= truncate(advisory.description, length: 50) diff --git a/app/views/platforms/platforms/_advisory.html.slim b/app/views/platforms/platforms/_advisory.html.slim new file mode 100644 index 000000000..96ea085c8 --- /dev/null +++ b/app/views/platforms/platforms/_advisory.html.slim @@ -0,0 +1,3 @@ +tr + td= link_to advisory.advisory_id, advisory_path(advisory) + td= truncate(advisory.description, length: 120) diff --git a/app/views/platforms/platforms/advisories.html.haml b/app/views/platforms/platforms/advisories.html.haml index 75255b69f..2f5858ff8 100644 --- a/app/views/platforms/platforms/advisories.html.haml +++ b/app/views/platforms/platforms/advisories.html.haml @@ -1,6 +1,7 @@ - set_meta_tags title: [title_object(@platform), t('layout.advisories.list_header')] = render 'submenu' -= render 'sidebar' -= render partial: 'advisories', object: @advisories -= will_paginate @advisories +.container + .row + = render partial: 'advisories', object: @advisories + = will_paginate @advisories diff --git a/app/views/platforms/platforms/clone.html.haml b/app/views/platforms/platforms/clone.html.haml deleted file mode 100644 index 1ea007b58..000000000 --- a/app/views/platforms/platforms/clone.html.haml +++ /dev/null @@ -1,17 +0,0 @@ --set_meta_tags title: [title_object(@platform), t('layout.platforms.clone_header')] -= render 'submenu' -= render 'sidebar' - -= form_for @cloned, url: make_clone_platform_path(@platform), html: { class: :form } do |f| - .leftlist= f.label :name, class: :label - .rightlist= f.text_field :name, class: 'text_field' - - .leftlist= f.label :description, class: :label - .rightlist= f.text_field :description, class: 'text_field' - - .both - - .button_block - = submit_tag t('layout.clone'), data: {'disable-with' => t('layout.processing')} - %span.text_button_padding= t("layout.or") - = link_to t("layout.cancel"), platform_path(@platform), class: "button" \ No newline at end of file diff --git a/app/views/platforms/platforms/clone.html.slim b/app/views/platforms/platforms/clone.html.slim new file mode 100644 index 000000000..b1467aeff --- /dev/null +++ b/app/views/platforms/platforms/clone.html.slim @@ -0,0 +1,18 @@ +- set_meta_tags title: [title_object(@platform), t('layout.platforms.clone_header')] += render 'submenu' + +.container + .row + = simple_form_for @cloned, url: make_clone_platform_path(@platform) do |f| + fieldset + + = f.input :name + = f.input :description, as: :text + + .button_block + button type="submit" class="btn btn-default" data-disable-with=t('layout.processing') + = t('layout.clone') + |   + = t('layout.or') + |   + = link_to t('layout.cancel'), platform_path(@platform) diff --git a/app/views/platforms/platforms/index.html.haml b/app/views/platforms/platforms/index.html.haml deleted file mode 100644 index 0d84f1c03..000000000 --- a/app/views/platforms/platforms/index.html.haml +++ /dev/null @@ -1,24 +0,0 @@ --set_meta_tags title: t('layout.platforms.list_header') -.row{ 'ng-controller' => 'PlatformsCtrl', 'ng-init' => "init(#{@platforms_count}, #{params[:page]})" } - .col-md-6.col-md-offset-3{ 'ng-cloak' => true } - = link_to t('layout.platforms.new'), new_platform_path, class: 'btn btn-primary' if can? :create, Platform - %table.table.table-hover.offset20 - %thead - %tr - %th - %th= t 'activerecord.attributes.platform.name' - %th= t 'activerecord.attributes.platform.distrib_type' - %tbody - %tr{ 'ng-repeat' => 'item in platforms' } - %td - %i.fa.fa-lg{ 'ng-class' => 'item.visibility_class' } - %td - %a{ 'ng-href' => "{{item.link}}" } - {{item.name}} - %td {{item.distrib_type}} - - = paginate( total_items: 'total_items', - page: 'page', - per_page: Platform.per_page, - ng_show: "total_items > #{Platform.per_page}", - select_page: "goToPage(page)" ) diff --git a/app/views/platforms/platforms/index.html.slim b/app/views/platforms/platforms/index.html.slim new file mode 100644 index 000000000..bc121e4fc --- /dev/null +++ b/app/views/platforms/platforms/index.html.slim @@ -0,0 +1,25 @@ +- set_meta_tags title: t('layout.platforms.list_header') +.row ng-controller='PlatformsCtrl' ng-init="init(#{@platforms_count}, #{params[:page]})" + .col-md-6.col-md-offset-3 ng-cloak=true + = link_to t('layout.platforms.new'), new_platform_path, class: 'btn btn-primary' if can? :create, Platform + table.table.table-hover.offset20 + thead + tr + th + th= t 'activerecord.attributes.platform.name' + th= t 'activerecord.attributes.platform.distrib_type' + tbody + tr ng-repeat='item in platforms' + td + i.fa.fa-lg ng-class='item.visibility_class' + td + a ng-href="{{item.link}}" + | {{item.name}} + td + | {{item.distrib_type}} + + = paginate( total_items: 'total_items', + page: 'page', + per_page: Platform.per_page, + ng_show: "total_items > #{Platform.per_page}", + select_page: "goToPage(page)" ) diff --git a/app/views/platforms/platforms/members.html.haml b/app/views/platforms/platforms/members.html.haml deleted file mode 100644 index d32434ed0..000000000 --- a/app/views/platforms/platforms/members.html.haml +++ /dev/null @@ -1,10 +0,0 @@ --set_meta_tags title: [title_object(@platform), t('layout.platforms.members')] -= render 'submenu' -= render 'sidebar' - -= render "shared/members_table", - remove_members_path: remove_members_platform_path(@platform), - remove_member_path: remove_member_platform_path(@platform), - add_member_path: add_member_platform_path(@platform), - members: @members.select{|u| u != @platform.owner}, - editable_object: @platform diff --git a/app/views/platforms/platforms/members.html.slim b/app/views/platforms/platforms/members.html.slim new file mode 100644 index 000000000..afd035472 --- /dev/null +++ b/app/views/platforms/platforms/members.html.slim @@ -0,0 +1,11 @@ +-set_meta_tags title: [title_object(@platform), t('layout.platforms.members')] += render 'submenu' + +.container + .row + = render "shared/members_table", + remove_members_path: remove_members_platform_path(@platform), + remove_member_path: remove_member_platform_path(@platform), + add_member_path: add_member_platform_path(@platform), + members: @members.select{|u| u != @platform.owner}, + editable_object: @platform diff --git a/app/views/shared/_angularjs_will_paginate.html.haml b/app/views/shared/_angularjs_will_paginate.html.haml deleted file mode 100644 index e0f72d5a0..000000000 --- a/app/views/shared/_angularjs_will_paginate.html.haml +++ /dev/null @@ -1,17 +0,0 @@ -/ Add to controller something like: -/ $scope.goToPage = (number) -> -/ $location.search('page', number) -#will_paginate{'ng-show' => 'pages'} - .pagination - %div{'ng-class' => "{'disabled': !page.active}", 'ng-repeat' => 'page in pages', 'ng-switch' => 'page.type'} - %a{'ng-switch-when' => 'previous_page', 'ng-click' => 'goToPage(page.number)', href: ''} - = t('datatables.previous_label') - %a{'ng-switch-when' => 'first', href: ''} - {{page.number}} - %a{'ng-switch-when' => 'page', 'ng-click' => 'goToPage(page.number)', href: ''} - {{page.number}} - %a{'ng-switch-when' => 'more', 'ng-click' => 'goToPage(page.number)', href: ''} … - %a{'ng-switch-when' => 'last', 'ng-click' => 'goToPage(page.number)', href: ''} - {{page.number}} - %a{'ng-switch-when' => 'next_page', 'ng-click' => 'goToPage(page.number)', href: ''} - = t('datatables.next_label') \ No newline at end of file diff --git a/app/views/shared/_angularjs_will_paginate.html.slim b/app/views/shared/_angularjs_will_paginate.html.slim new file mode 100644 index 000000000..6ca9b02f6 --- /dev/null +++ b/app/views/shared/_angularjs_will_paginate.html.slim @@ -0,0 +1,20 @@ +/ Add to controller something like: +/ $scope.goToPage = (number) -> +/ $location.search('page', number) +ul.pagination ng-show='pages' + li ng-class="{'disabled': !page.active}" ng-repeat='page in pages' ng-switch='page.type' + a ng-switch-when='previous_page' ng-hide='page.active' + = t('datatables.previous_label') + a ng-switch-when='previous_page' ng-show='page.active' ng-click='goToPage(page.number)' + = t('datatables.previous_label') + a ng-switch-when='first' + | {{page.number}} + a ng-switch-when='page' ng-click='goToPage(page.number)' + | {{page.number}} + a ng-switch-when='more' ng-click='goToPage(page.number)' … + a ng-switch-when='last' ng-click='goToPage(page.number)' + | {{page.number}} + a ng-switch-when='next_page' ng-hide='page.active' + = t('datatables.next_label') + a ng-switch-when='next_page' ng-show='page.active' ng-click='goToPage(page.number)' + = t('datatables.next_label') diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index ebc845cb9..5c2ef12c8 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -3,7 +3,6 @@ en: platforms: contents: Contents contents_of: Contents of - search_contents: Search name of file/folder... admin_id: Owner build_all: Build all list: List @@ -95,3 +94,15 @@ en: visibility_types: open: Public hidden: Private + + simple_form: + labels: + platform: + term: Search + admin_id: Owner + placeholders: + platform: + term: Enter the name of file or folder here. + + + diff --git a/config/locales/models/platform.ru.yml b/config/locales/models/platform.ru.yml index a3b38a16d..335d67ed3 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -95,3 +95,12 @@ ru: visibility_types: open: Публичный hidden: Приватный + + simple_form: + labels: + platform: + term: Искать + admin_id: Владелец + placeholders: + platform: + term: Введите имя файла или папки здесь.