diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 9f112f31d..c42bbaf25 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -1384,3 +1384,11 @@ hr.bootstrap { filter: alpha(opacity=20); } } + +time.js-relative-date { + display: block; +} + +div.reloader { + float: right; +} diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index a3cf75b0f..bc1238367 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -25,7 +25,7 @@ class Projects::BuildListsController < Projects::BaseController def index @action_url = @project ? search_project_build_lists_path(@project) : search_build_lists_path @filter = BuildList::Filter.new(@project, current_user, params[:filter] || {}) - @build_lists = @filter.find.scoped(:include => [:save_to_platform, :project, :user, :arch]) + @build_lists = @filter.find.includes [:save_to_platform, :save_to_repository, :arch, :user => [:groups], :project => [:owner]] @build_lists = @build_lists.recent.paginate :page => params[:page] @build_server_status = begin diff --git a/app/views/projects/build_lists/_build_list.html.haml b/app/views/projects/build_lists/_build_list.html.haml index 75fcf3b34..1ac0852b7 100644 --- a/app/views/projects/build_lists/_build_list.html.haml +++ b/app/views/projects/build_lists/_build_list.html.haml @@ -1,6 +1,10 @@ %tr{:id => "row#{build_list_counter}", :class => "#{build_list_status_color(build_list.status)}"} %td= link_to (build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")), build_list - %td= build_list.human_status + %td + = build_list.human_status + - if BuildList::HUMAN_STATUSES[build_list.status].in? [:build_pending, :build_started, :build_publish] + %time.js-relative-date{:datetime => build_list.updated_at.strftime("%FT%T%:z"), :title => build_list.updated_at.strftime("%F %T")} + = build_list.updated_at.strftime "%F %T" %td= link_to build_list.project.name_with_owner, build_list.project %td= build_list_version_link(build_list) %td= link_to "#{build_list.save_to_platform.name}/#{build_list.save_to_repository.name}", [build_list.save_to_platform, build_list.save_to_repository] diff --git a/app/views/projects/build_lists/index.html.haml b/app/views/projects/build_lists/index.html.haml index d2cbc2654..61f04fbe6 100644 --- a/app/views/projects/build_lists/index.html.haml +++ b/app/views/projects/build_lists/index.html.haml @@ -1,5 +1,11 @@ -set_meta_tags :title => t('.title') -/ #myTable + +%div.reloader + = label_tag :autoreload do + = check_box_tag :autoreload, true, true + = t("layout.autoreload_page") +.both + %table.tablesorter{:cellpadding => "0", :cellspacing => "0"} %thead %tr @@ -13,6 +19,57 @@ %tbody= render :partial => 'projects/build_lists/build_list', :collection => @build_lists .both +:javascript + $(function(){ + // from jQuery.timeago + var parseIso8601 = function(iso8601) { + var s = $.trim(iso8601); + s = s.replace(/\.\d+/,""); // remove milliseconds + s = s.replace(/-/,"/").replace(/-/,"/"); + s = s.replace(/T/," ").replace(/Z/," UTC"); + s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400 + return new Date(s); + } + var strTimeBetween = function(dt, dt1) { + + var formatNumber = function(num) { + return (num < 10) ? "0%d".replace("%d", num) : num + } + + var seconds = Math.abs(dt1 - dt) / 1000; + var minutes = seconds / 60; + var hours = minutes / 60; + minutes = Math.round(minutes % 60); + hours = Math.round(hours); + + return "%d:%d".replace("%d", formatNumber(hours)) + .replace("%d", formatNumber(minutes)); + } + // TODO Very, very ugly method. + var now = (new Date).getTime(); + $("time.js-relative-date").each(function() { + var time = parseIso8601($(this).attr('datetime')).getTime(); + $(this).text(strTimeBetween(time, now)); + }); + + var t = null; + + var reloadChange = function() { + if ($(this).is(':checked')) { + //reload page every 1 minute + t = setTimeout(function() { + window.location.reload(); + }, 60000); + } else { + clearTimeout(t); + } + } + + $('#autoreload').on('change', reloadChange) + .trigger('change'); + + }); + = will_paginate @build_lists = render 'filter' diff --git a/config/locales/layout.en.yml b/config/locales/layout.en.yml index d5ff40b31..5268e0cc3 100644 --- a/config/locales/layout.en.yml +++ b/config/locales/layout.en.yml @@ -1,5 +1,6 @@ en: layout: + autoreload_page: Update page automatically read_more: Read more turned_on: on turned_off: off diff --git a/config/locales/layout.ru.yml b/config/locales/layout.ru.yml index a9782afcd..29247306a 100644 --- a/config/locales/layout.ru.yml +++ b/config/locales/layout.ru.yml @@ -1,5 +1,6 @@ ru: layout: + autoreload_page: Автоматически обновлять страницу read_more: Читать дальше turned_on: включены turned_off: выключены