[#369] advisories page
This commit is contained in:
parent
a74aa8789e
commit
82d2d18a36
|
@ -0,0 +1,27 @@
|
||||||
|
RosaABF.controller('AdvisoryCtrl', ['$scope', '$http', function($scope, $http) {
|
||||||
|
$scope.total_items = null;
|
||||||
|
$scope.page = null;
|
||||||
|
$scope.advisories = null;
|
||||||
|
$scope.q = null;
|
||||||
|
|
||||||
|
$scope.init = function(total_items, page, q) {
|
||||||
|
$scope.total_items = total_items;
|
||||||
|
$scope.page = page;
|
||||||
|
$scope.q = q;
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.getAdvisories = function() {
|
||||||
|
$http.get(Routes.advisories_path({format: 'json', page: $scope.page, q: $scope.q})).then(function(res) {
|
||||||
|
$scope.page = res.data.page;
|
||||||
|
$scope.total_items = parseInt(res.data.advisories_count, 10);
|
||||||
|
$scope.advisories = res.data.advisories;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.goToPage = function(page) {
|
||||||
|
$scope.page = page;
|
||||||
|
$scope.getAdvisories();
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.getAdvisories();
|
||||||
|
}]);
|
|
@ -1,4 +1,4 @@
|
||||||
RosaABF.controller('PlatformsCtrl', ['$scope', '$http', '$timeout', function($scope, $http, $timeout) {
|
RosaABF.controller('PlatformsCtrl', ['$scope', '$http', function($scope, $http) {
|
||||||
$scope.total_items = null;
|
$scope.total_items = null;
|
||||||
$scope.page = null;
|
$scope.page = null;
|
||||||
$scope.platforms = null;
|
$scope.platforms = null;
|
||||||
|
|
|
@ -41,6 +41,7 @@ var _locales = {
|
||||||
'notification.issue_assign': 'Вам назначили задачу ',
|
'notification.issue_assign': 'Вам назначили задачу ',
|
||||||
|
|
||||||
'read_more': 'Читать дальше',
|
'read_more': 'Читать дальше',
|
||||||
|
'no_results_for_search': 'По запросу "%1" ничего не найдено.',
|
||||||
|
|
||||||
},
|
},
|
||||||
<%I18n.locale = :en%>
|
<%I18n.locale = :en%>
|
||||||
|
@ -83,6 +84,6 @@ var _locales = {
|
||||||
'notification.issue_assign': 'You have been assigned to issue ',
|
'notification.issue_assign': 'You have been assigned to issue ',
|
||||||
|
|
||||||
'read_more': 'Read more',
|
'read_more': 'Read more',
|
||||||
|
'no_results_for_search': 'Nothing found for "%1".',
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -1,14 +1,18 @@
|
||||||
class AdvisoriesController < ApplicationController
|
class AdvisoriesController < ApplicationController
|
||||||
|
layout 'bootstrap', only: [:index]
|
||||||
|
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
skip_before_filter :authenticate_user! if APP_CONFIG['anonymous_access']
|
skip_before_filter :authenticate_user! if APP_CONFIG['anonymous_access']
|
||||||
load_resource find_by: :advisory_id
|
load_resource find_by: :advisory_id
|
||||||
authorize_resource
|
authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@advisories = @advisories.includes(:platforms).search(params[:q]).
|
@advisories = @advisories.includes(:platforms).search(params[:q]).uniq
|
||||||
uniq.paginate(page: params[:page])
|
@advisories_count = @advisories.count
|
||||||
|
@advisories = @advisories.paginate(page: current_page, per_page: Advisory.per_page)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
|
format.json
|
||||||
format.atom
|
format.atom
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Advisory < ActiveRecord::Base
|
class Advisory < ActiveRecord::Base
|
||||||
self.include_root_in_json = false
|
self.include_root_in_json = false
|
||||||
|
self.per_page = 30
|
||||||
|
|
||||||
has_and_belongs_to_many :platforms
|
has_and_belongs_to_many :platforms
|
||||||
has_and_belongs_to_many :projects
|
has_and_belongs_to_many :projects
|
||||||
|
|
|
@ -1,32 +1,22 @@
|
||||||
%table#myTable.tablesorter.advisories.static-search{cellspacing: "0", cellpadding: "0"}
|
.row.offset10.boffset20
|
||||||
|
.col-xs-8
|
||||||
|
= text_field_tag 'q', params[:q], placeholder: t('layout.advisories.search'),
|
||||||
|
class: 'form-control text-muted', 'ng-model' => 'q', 'ng-change' => 'goToPage(1)'
|
||||||
|
|
||||||
|
%table.table.table-hover{ 'ng-cloak' => true }
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
%th.th1= t("activerecord.attributes.advisory.advisory_id")
|
%th= t 'activerecord.attributes.advisory.advisory_id'
|
||||||
%th.th2= t("layout.advisories.affected_versions")
|
%th= t 'layout.advisories.affected_versions'
|
||||||
%th.th3= t("activerecord.attributes.advisory.description")
|
%th= t 'activerecord.attributes.advisory.description'
|
||||||
%tr.search
|
|
||||||
-# TODO: change filter to Backbone.js
|
|
||||||
%th{colspan: 3, rowspan: 1}
|
|
||||||
= form_tag advisories_path, method: :get do |f|
|
|
||||||
= text_field_tag('q', params[:q], placeholder: t('layout.advisories.search'), class: params[:q].present? ? 'black' : 'gray', style: 'width:600px;')
|
|
||||||
= submit_tag t('layout.search.header'), data: {'disable-with' => t('layout.processing')}
|
|
||||||
=# link_to t('layout.back'), advisories_path, class: 'button'
|
|
||||||
= button_to t('layout.clear'), {action: :index} , method: :get
|
|
||||||
|
|
||||||
%tbody
|
%tbody
|
||||||
- if list.size > 0
|
%tr{ 'ng-repeat' => 'item in advisories' }
|
||||||
= render partial: 'list_item', collection: list, as: :advisory
|
%td
|
||||||
- else
|
%a{ 'ng-href' => '{{item.link}}' } {{item.id}}
|
||||||
%tr.odd
|
%td
|
||||||
%td.no_results{colspan: 3}
|
%p{ 'ng-repeat' => 'pl in item.platforms' }
|
||||||
= t("layout.search.no_results", query: params[:q])
|
%a{ 'ng-href' => '{{pl.link}}' } {{pl.name}}
|
||||||
|
%td {{item.description}}
|
||||||
|
|
||||||
:javascript
|
%tr{ 'ng-show' => 'advisories.length === 0' }
|
||||||
$(function() {
|
%td{ colspan: 3 } {{'no_results_for_search' | i18n:q}}
|
||||||
var $search = $('tr.search > th input[type="text"]');
|
|
||||||
$search.on('blur focus', function() {
|
|
||||||
if ($search.val() === '') {
|
|
||||||
$search.toggleClass('gray black');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
- content_for :submenu do
|
- content_for :submenu do
|
||||||
- act = action_name.to_sym; contr = controller_name.to_sym
|
- act = action_name.to_sym; contr = controller_name.to_sym
|
||||||
.left
|
%nav.navbar.navbar-default.submenu{role: "navigation"}
|
||||||
= @advisory.advisory_id if @advisory.present?
|
.container-fluid
|
||||||
%nav
|
.navbar-header
|
||||||
%ul
|
%ul.nav.navbar-nav
|
||||||
%li= link_to t('layout.list'), advisories_path, class: act.in?([:index]) ? 'active' : nil
|
- if @advisory.present?
|
||||||
|
%li= @advisory.advisory_id
|
||||||
|
- else
|
||||||
|
%li{ class: ('active' if act.in? [:index]) }
|
||||||
|
= link_to t('layout.list'), advisories_path, class: act.in?([:index]) ? 'active' : nil
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
- set_meta_tags title: t('layout.advisories.list_header')
|
- set_meta_tags title: t('layout.advisories.list_header')
|
||||||
- render partial: 'submenu'
|
- render partial: 'submenu'
|
||||||
%h3.fix
|
.row
|
||||||
= t("layout.advisories.list_header")
|
.container{ 'ng-controller' => 'AdvisoryCtrl',
|
||||||
= link_to image_tag("rss.ico", width: '15px', height: '15px', class: 'atom_icon'),
|
'ng-init' => "init(#{@advisories_count}, #{params[:page]}, #{params[:q].presence || 'null'})" }
|
||||||
APP_CONFIG['anonymous_access'] ? advisories_path(format: 'atom') : advisories_path(format: 'atom', token: current_user.authentication_token)
|
%h3
|
||||||
= render partial: 'list', object: @advisories
|
= t 'layout.advisories.list_header'
|
||||||
= will_paginate @advisories
|
= link_to image_tag("rss.ico", width: '15px', height: '15px', class: 'atom_icon'),
|
||||||
|
APP_CONFIG['anonymous_access'] ? advisories_path(format: 'atom') : advisories_path(format: 'atom', token: current_user.authentication_token)
|
||||||
|
= render partial: 'list', object: @advisories
|
||||||
|
= paginate( total_items: 'total_items',
|
||||||
|
page: 'page',
|
||||||
|
per_page: Advisory.per_page,
|
||||||
|
ng_show: "total_items > #{Advisory.per_page}",
|
||||||
|
select_page: "goToPage(page)" )
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
json.advisories do
|
||||||
|
json.array!(@advisories) do |item|
|
||||||
|
json.cache! item, expires_in: 10.minutes do
|
||||||
|
json.id item.advisory_id
|
||||||
|
json.link advisory_path(item)
|
||||||
|
json.description truncate(item.description, length: 100)
|
||||||
|
json.platforms do
|
||||||
|
json.array!(item.platforms) do |pl|
|
||||||
|
json.name platform_printed_name(pl)
|
||||||
|
json.link platform_path(pl)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
json.page params[:page]
|
||||||
|
json.advisories_count @advisories_count
|
Loading…
Reference in New Issue