From 1ae14ecd86e9c037b004c0667efc8b2bcb95dc50 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 24 Oct 2014 03:27:30 +0400 Subject: [PATCH] #369: use bootstrap for Platforms#show page --- Gemfile | 1 + Gemfile.lock | 5 ++ .../platform_sys_repos_controller.js.coffee | 26 ++++++ .../platforms/platforms_controller.rb | 2 +- app/helpers/platforms_helper.rb | 1 + app/models/platform.rb | 3 +- app/views/platforms/base/_submenu.html.haml | 79 ++++++++++++++++++- .../platforms/_connection_info.html.haml | 37 --------- app/views/platforms/platforms/show.html.haml | 37 --------- app/views/platforms/platforms/show.html.slim | 54 +++++++++++++ .../platforms/platforms/show.json.jbuilder | 6 ++ 11 files changed, 172 insertions(+), 79 deletions(-) create mode 100644 app/assets/javascripts/angular-new/platforms/platform_sys_repos_controller.js.coffee delete mode 100644 app/views/platforms/platforms/_connection_info.html.haml delete mode 100644 app/views/platforms/platforms/show.html.haml create mode 100644 app/views/platforms/platforms/show.html.slim create mode 100644 app/views/platforms/platforms/show.json.jbuilder diff --git a/Gemfile b/Gemfile index e5207bafa..ee41bfb3b 100644 --- a/Gemfile +++ b/Gemfile @@ -55,6 +55,7 @@ gem "haml-rails", '~> 0.5' gem 'jquery-rails', '~> 2.3' gem 'jquery-migrate-rails' gem 'ruby-haml-js', '~> 0.0.5' +gem 'slim' gem 'friendly_id', '~> 5.0' gem 'rack-throttle', '~> 0.3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 9be1acfb0..3201da1dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -461,6 +461,9 @@ GEM thin (~> 1.5.0) skype (0.2.8) tmp_cache + slim (2.1.0) + temple (~> 0.6.9) + tilt (>= 1.3.3, < 2.1) soundmanager-rails (1.0.1) sprockets (2.11.0) hike (~> 1.2) @@ -476,6 +479,7 @@ GEM sqlite3 (>= 1.3.3) state_machine (1.2.0) stringex (2.5.2) + temple (0.6.9) test_after_commit (0.2.5) activerecord (>= 3.2) therubyracer (0.12.1) @@ -610,6 +614,7 @@ DEPENDENCIES shoulda-matchers sitemap_generator skype + slim soundmanager-rails state_machine (~> 1.2) test_after_commit diff --git a/app/assets/javascripts/angular-new/platforms/platform_sys_repos_controller.js.coffee b/app/assets/javascripts/angular-new/platforms/platform_sys_repos_controller.js.coffee new file mode 100644 index 000000000..3134b6ec3 --- /dev/null +++ b/app/assets/javascripts/angular-new/platforms/platform_sys_repos_controller.js.coffee @@ -0,0 +1,26 @@ +RosaABF.controller 'PlatformSysReposController', ['$scope', '$http', ($scope, $http) -> + + $scope.init = (platform_id) -> + path = Routes.platform_path platform_id + $http.get(path, { format: 'json' }).success (res) -> + $scope.list = res.list + $scope.platforms = res.platforms + $scope.arches = res.arches + + $scope.platform = res.platforms[0] + $scope.arch = res.arches[0] + $scope.updateCommand() + + $scope.updateCommand = -> + if $scope.platform && $scope.arch + $scope.command = $scope.list[$scope.platform][$scope.arch] + else + $scope.command = '' + + + $scope.selectAll = ($event) -> + target = $($event.currentTarget) + target.select() + false + +] \ No newline at end of file diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 42e867e85..11034d0c9 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -1,6 +1,6 @@ class Platforms::PlatformsController < Platforms::BaseController include FileStoreHelper - layout 'bootstrap', only: [:index] + layout 'bootstrap'#, only: [:index] before_filter :authenticate_user! skip_before_filter :authenticate_user!, only: [:advisories, :members, :show] if APP_CONFIG['anonymous_access'] diff --git a/app/helpers/platforms_helper.rb b/app/helpers/platforms_helper.rb index 51131915a..68ac50fce 100644 --- a/app/helpers/platforms_helper.rb +++ b/app/helpers/platforms_helper.rb @@ -1,4 +1,5 @@ module PlatformsHelper + def repository_name_postfix(platform) return "" unless platform return platform.released ? '/update' : '/release' diff --git a/app/models/platform.rb b/app/models/platform.rb index 0bf0772f1..080728199 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -142,10 +142,11 @@ class Platform < ActiveRecord::Base # TODO: rename method or create separate methods for mdv and rhel # Platform.main.opened.where(distrib_type: APP_CONFIG['distr_types'].first).each do |pl| + arches = Arch.all.to_a Platform.main.opened.each do |pl| urpmi_commands[pl.name] = {} # FIXME should support restricting access to the hidden platform - Arch.all.each do |arch| + arches.each do |arch| tail = "/#{arch.name}/#{repository_name}/release" command = add_commands ? "urpmi.addmedia #{name} " : '' command << "#{APP_CONFIG['downloads_url']}/#{name}/repository/#{pl.name}#{tail}" diff --git a/app/views/platforms/base/_submenu.html.haml b/app/views/platforms/base/_submenu.html.haml index 072971af2..7d0337e2e 100644 --- a/app/views/platforms/base/_submenu.html.haml +++ b/app/views/platforms/base/_submenu.html.haml @@ -1,5 +1,78 @@ +/ - content_for :submenu do +/ - act = action_name.to_sym; contr = controller_name.to_sym +/ .left= platform_printed_name(@platform) +/ %nav +/ %ul + - content_for :submenu do - act = action_name.to_sym; contr = controller_name.to_sym - .left= platform_printed_name(@platform) - %nav - %ul + %nav.navbar.navbar-default{ role: 'navigation' } + .container-fluid + / Brand and toggle get grouped for better mobile display + .navbar-header + %button.navbar-toggle{ 'data-target' => '#submenu-navbar-collapse', 'data-toggle' => 'collapse', type: 'button' } + %span.sr-only Toggle navigation + %span.icon-bar + %span.icon-bar + %span.icon-bar + .navbar-brand + = link_to platform_printed_name(@platform), @platform + / Collect the nav links, forms, and other content for toggling + #submenu-navbar-collapse.collapse.navbar-collapse + %ul.nav.navbar-nav.left-border + + %li{class: (act == :show && contr == :platforms) ? 'active' : ''} + = link_to t("layout.platforms.about"), platform_path(@platform) + %li{class: (contr == :repositories) ? 'active' : ''} + = link_to t("layout.repositories.list_header"), platform_repositories_path(@platform) + %li{class: (contr == :contents) ? 'active' : ''} + = link_to t('layout.platforms.contents'), platform_contents_path(@platform) + - if can? :show, @platform + %li{class: (act == :index && contr == :maintainers) ? 'active' : nil} + = link_to t("layout.platforms.maintainers"), platform_maintainers_path(@platform) + %li{class: (contr == :mass_builds) ? 'active' : ''} + = link_to t("layout.platforms.mass_build"), platform_mass_builds_path(@platform) + - if can? :read, @platform.products.build + %li{class: (contr == :products) ? 'active' : ''} + = link_to t("layout.products.list_header"), platform_products_path(@platform) + - if can? :advisories, @platform + %li{class: (contr == :platforms and act == :advisories) ? 'active' : ''} + = link_to t("layout.advisories.list_header"), advisories_platform_path(@platform) + - if can? :update, @platform + %li{class: (act == :edit && contr == :platforms) ? 'active' : nil} + = link_to t("platform_menu.settings"), edit_platform_path(@platform) + - if can? :members, @platform + %li{class: (act == :members && contr == :platforms) ? 'active' : nil} + = link_to t("layout.platforms.members"), members_platform_path(@platform) + - if can? :edit, @platform + %li{class: (act == :index && contr == :key_pairs) ? 'active' : ''} + = link_to t("layout.key_pairs.header"), platform_key_pairs_path(@platform) + %li{class: (contr == :tokens) ? 'active' : ''} + = link_to t('layout.tokens.header'), platform_tokens_path(@platform) + + / - if @project.parent + / %li + / = link_to project_path(@project.parent), class: 'small' do + / = fa_icon 'code-fork' + / = @project.parent.name_with_owner + / %li{ class: ('active' if act.in?([:show, :edit, :branches, :tags]) && contr.in?([:trees, :blobs]) || contr == :commits) } + / = link_to t('project_menu.code'), tree_path(@project, treeish) + / - if @project.is_package and can?(:read, @project => BuildList) + / %li{ class: ('active' if contr == :build_lists) } + / = link_to t('project_menu.builds'), project_build_lists_path(@project) + + / - if @project.has_issues + / %li{ class: ('active' if contr == :issues) } + / = link_to t('project_menu.tracker', count: @opened_issues_count), project_issues_path(@project) + / %li{ class: ('active' if contr == :pull_requests) } + / =link_to t('project_menu.pull_requests', count: @opened_pull_requests_count), project_pull_requests_path(@project) + / - if @project.has_wiki + / %li{ class: ('active' if contr == :wiki) } + / = link_to t('project_menu.wiki'), project_wiki_index_path(@project) + / %li=# link_to t('project_menu.readme'), '#' #pending + / - if can? :update, @project + / %li{ class: ('active' if act == :edit && contr == :projects) } + / = link_to t('project_menu.settings'), edit_project_path(@project) + / / /.navbar-collapse + / / /.container-fluid + diff --git a/app/views/platforms/platforms/_connection_info.html.haml b/app/views/platforms/platforms/_connection_info.html.haml deleted file mode 100644 index c2569c7cf..000000000 --- a/app/views/platforms/platforms/_connection_info.html.haml +++ /dev/null @@ -1,37 +0,0 @@ -- platforms = Platform.main.opened.where(distrib_type: APP_CONFIG['distr_types'].first).order('name ASC') - -- if platforms.count > 0 - .command_select - %h3= t("layout.platforms.sys_repos_header") - - .leftlist= label_tag :platform, t("layout.platforms.target_platform") - .rightlist= select_tag :platform, options_from_collection_for_select(platforms, :name, :name, platforms.first.id) - .both - - - arches = Arch.order('name ASC') - .leftlist= label_tag :arch, t("layout.platforms.target_architecture") - .rightlist= select_tag :arch, options_from_collection_for_select(arches, :name, :name, arches.first.id) - .both - - .rightlist - %textarea{id: 'command_string', readonly: 'readonly'} - .both - - :javascript - $(document).ready(function(){ - var path_getter = function() { - var list = #{@platform.urpmi_list(request.host).to_json}; - var $platform = $("select#platform"); - var $arch = $("select#arch"); - - $('#command_string').val(list[$platform.val()][$arch.val()]); - // alert('hello'); - } - $("select#platform").on('change', path_getter); - $("select#arch").on('change', path_getter); - $("textarea#command_string").on('click', function() { - this.select(); - }); - path_getter(); - }); - diff --git a/app/views/platforms/platforms/show.html.haml b/app/views/platforms/platforms/show.html.haml deleted file mode 100644 index 00dd0148b..000000000 --- a/app/views/platforms/platforms/show.html.haml +++ /dev/null @@ -1,37 +0,0 @@ --set_meta_tags title: title_object(@platform) -= render 'submenu' -= render 'sidebar' - -%h3.fix - = t 'layout.platforms.about' - = link_to @platform.name, platform_contents_path(@platform) - -%p= @platform.description - -%table.tablesorter.unbordered - - if @platform.parent - %tr - %td - %b= "#{t("activerecord.attributes.platform.parent")}:" - %td= link_to @platform.parent.description, platform_path(@platform.parent) - %tr - %td - %b= "#{t('layout.platforms.owner')}:" - %td= link_to @platform.owner.try(:name), url_for(@platform.owner) - %tr - %td - %b= "#{t('layout.platforms.visibility')}:" - %td= t("layout.visibilities.#{@platform.visibility}") - %tr - %td - %b= "#{t('layout.platforms.platform_type')}:" - %td= @platform.platform_type - %tr - %td - %b= "#{t('layout.platforms.distrib_type')}:" - %td= @platform.distrib_type - -.buttons_block - = link_to I18n.t("layout.platforms.clone"), clone_platform_path(@platform), class: "button left_floated" if can? :clone, @platform - -= render 'connection_info' if @platform.platform_type == 'personal' and @platform.visibility == 'open' diff --git a/app/views/platforms/platforms/show.html.slim b/app/views/platforms/platforms/show.html.slim new file mode 100644 index 000000000..25c400974 --- /dev/null +++ b/app/views/platforms/platforms/show.html.slim @@ -0,0 +1,54 @@ +-set_meta_tags title: title_object(@platform) += render 'submenu' +/ = render 'sidebar' + +.container + .row + .col-md-6 + h3 + = t('layout.platforms.about') + |   + = link_to @platform.name, platform_contents_path(@platform) + dl.dl-horizontal + dt= t('activerecord.attributes.platform.description') + dd= @platform.description + + - if @platform.parent + dt= t('activerecord.attributes.platform.parent') + dd= link_to @platform.parent.description, platform_path(@platform.parent) + + dt= t('layout.platforms.owner') + dd= link_to @platform.owner.try(:name), url_for(@platform.owner) + + dt= t('layout.platforms.visibility') + dd= t("layout.visibilities.#{@platform.visibility}") + + dt= t('layout.platforms.platform_type') + dd= @platform.platform_type + + dt= t('layout.platforms.distrib_type') + dd= @platform.distrib_type + + - if can? :clone, @platform + dt + dd + a.btn.btn-primary href=clone_platform_path(@platform) + = t('layout.platforms.clone') + + - if @platform.platform_type == 'personal' and @platform.visibility == 'open' + .col-md-6 ng-controller='PlatformSysReposController' ng-init="init(#{@platform.id})" + h3= t('layout.platforms.sys_repos_header') + dl.dl-horizontal + dt= t('layout.platforms.target_platform') + dd + select ng-model='platform' ng-change='updateCommand()' + option ng-repeat='platform in platforms' ng-value='platform' + | {{ platform }} + + dt= t('layout.platforms.target_architecture') + dd + select ng-model='arch' ng-change='updateCommand()' + option ng-repeat='arch in arches' ng-value='arch' + | {{ arch }} + br + textarea.form-control readonly='readonly' ng-model='command' rows=3 ng-click='selectAll($event)' diff --git a/app/views/platforms/platforms/show.json.jbuilder b/app/views/platforms/platforms/show.json.jbuilder new file mode 100644 index 000000000..d16bdd018 --- /dev/null +++ b/app/views/platforms/platforms/show.json.jbuilder @@ -0,0 +1,6 @@ +platforms = Platform.main.opened. + where(distrib_type: APP_CONFIG['distr_types'].first).order('name ASC') + +json.list @platform.urpmi_list(request.host) +json.platforms platforms.pluck(:name) +json.arches Arch.order('name ASC').pluck(:name)