[#369] advisories page

This commit is contained in:
Alexander Machehin 2014-06-27 17:43:31 +06:00
parent a74aa8789e
commit 82d2d18a36
9 changed files with 95 additions and 43 deletions

View File

@ -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();
}]);

View File

@ -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.page = null;
$scope.platforms = null;

View File

@ -41,6 +41,7 @@ var _locales = {
'notification.issue_assign': 'Вам назначили задачу ',
'read_more': 'Читать дальше',
'no_results_for_search': 'По запросу "%1" ничего не найдено.',
},
<%I18n.locale = :en%>
@ -83,6 +84,6 @@ var _locales = {
'notification.issue_assign': 'You have been assigned to issue ',
'read_more': 'Read more',
'no_results_for_search': 'Nothing found for "%1".',
}
};

View File

@ -1,14 +1,18 @@
class AdvisoriesController < ApplicationController
layout 'bootstrap', only: [:index]
before_filter :authenticate_user!
skip_before_filter :authenticate_user! if APP_CONFIG['anonymous_access']
load_resource find_by: :advisory_id
authorize_resource
def index
@advisories = @advisories.includes(:platforms).search(params[:q]).
uniq.paginate(page: params[:page])
@advisories = @advisories.includes(:platforms).search(params[:q]).uniq
@advisories_count = @advisories.count
@advisories = @advisories.paginate(page: current_page, per_page: Advisory.per_page)
respond_to do |format|
format.html
format.json
format.atom
end
end

View File

@ -1,5 +1,6 @@
class Advisory < ActiveRecord::Base
self.include_root_in_json = false
self.per_page = 30
has_and_belongs_to_many :platforms
has_and_belongs_to_many :projects

View File

@ -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
%tr
%th.th1= t("activerecord.attributes.advisory.advisory_id")
%th.th2= t("layout.advisories.affected_versions")
%th.th3= 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
%th= t 'activerecord.attributes.advisory.advisory_id'
%th= t 'layout.advisories.affected_versions'
%th= t 'activerecord.attributes.advisory.description'
%tbody
- if list.size > 0
= render partial: 'list_item', collection: list, as: :advisory
- else
%tr.odd
%td.no_results{colspan: 3}
= t("layout.search.no_results", query: params[:q])
%tr{ 'ng-repeat' => 'item in advisories' }
%td
%a{ 'ng-href' => '{{item.link}}' } {{item.id}}
%td
%p{ 'ng-repeat' => 'pl in item.platforms' }
%a{ 'ng-href' => '{{pl.link}}' } {{pl.name}}
%td {{item.description}}
:javascript
$(function() {
var $search = $('tr.search > th input[type="text"]');
$search.on('blur focus', function() {
if ($search.val() === '') {
$search.toggleClass('gray black');
}
});
});
%tr{ 'ng-show' => 'advisories.length === 0' }
%td{ colspan: 3 } {{'no_results_for_search' | i18n:q}}

View File

@ -1,7 +1,11 @@
- content_for :submenu do
- act = action_name.to_sym; contr = controller_name.to_sym
.left
= @advisory.advisory_id if @advisory.present?
%nav
%ul
%li= link_to t('layout.list'), advisories_path, class: act.in?([:index]) ? 'active' : nil
%nav.navbar.navbar-default.submenu{role: "navigation"}
.container-fluid
.navbar-header
%ul.nav.navbar-nav
- 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

View File

@ -1,8 +1,15 @@
- set_meta_tags title: t('layout.advisories.list_header')
- render partial: 'submenu'
%h3.fix
= t("layout.advisories.list_header")
.row
.container{ 'ng-controller' => 'AdvisoryCtrl',
'ng-init' => "init(#{@advisories_count}, #{params[:page]}, #{params[:q].presence || 'null'})" }
%h3
= t 'layout.advisories.list_header'
= 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
= will_paginate @advisories
= paginate( total_items: 'total_items',
page: 'page',
per_page: Advisory.per_page,
ng_show: "total_items > #{Advisory.per_page}",
select_page: "goToPage(page)" )

View File

@ -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