[#369] new build list page: add last build lists

This commit is contained in:
Alexander Machehin 2014-11-05 15:52:16 +05:00
parent b10387c91e
commit d0ab09902c
11 changed files with 153 additions and 230 deletions

View File

@ -7,7 +7,7 @@ NewBuildListController = (dataservice, $http) ->
result.length is 1
defaultSaveToRepository = ->
return null unless vm.save_to_repositories
return {} unless vm.save_to_repositories
return vm.save_to_repositories[0] unless vm.save_to_repository_id
result = _.select(vm.save_to_repositories, (e) ->
@ -17,7 +17,7 @@ NewBuildListController = (dataservice, $http) ->
result[0]
defaultProjectVersion = ->
return null unless vm.project_versions
return {} unless vm.project_versions
result = _.select(vm.project_versions, (e) ->
e.name is vm.project_version_name
@ -25,6 +25,7 @@ NewBuildListController = (dataservice, $http) ->
return vm.project_versions[0] if result.length is 0
result[0]
vm = this
vm.selectSaveToRepository = ->
@ -44,7 +45,9 @@ NewBuildListController = (dataservice, $http) ->
if pl.id isnt vm.build_for_platform_id
r.checked = false
if pl.id is vm.build_for_platform_id or
(!vm.is_build_for_main_platform and vm.project_version.name is pl.name)
(!vm.is_build_for_main_platform and
vm.project_version and
vm.project_version.name is pl.name)
r.checked = true if r.name == 'main' or r.name == 'base'
)
)
@ -138,8 +141,32 @@ NewBuildListController = (dataservice, $http) ->
vm.selected_extra_build_list = null
false
vm.updateFilterOwner = ->
vm.last_build_lists_filter.owner = !vm.last_build_lists_filter.owner;
vm.updateLastBuilds()
vm.updateFilterStatus = ->
vm.last_build_lists_filter.status = !vm.last_build_lists_filter.status;
vm.updateLastBuilds()
vm.updateLastBuilds = ->
path = Routes.list_project_build_lists_path(
{
name_with_owner: vm.name_with_owner,
page: vm.last_build_lists_filter.page
owner_filter: vm.last_build_lists_filter.owner
status_filter: vm.last_build_lists_filter.status
}
)
$http.get(path).then (response) ->
vm.last_build_lists = response.data.build_lists
vm.total_items = response.data.total_items
false
init = (dataservice) ->
vm.name_with_owner = dataservice.name_with_owner
vm.build_for_platform_id = dataservice.build_for_platform_id
vm.platforms = dataservice.platforms
vm.save_to_repositories = dataservice.save_to_repositories
@ -164,6 +191,10 @@ NewBuildListController = (dataservice, $http) ->
vm.is_build_for_main_platform = isBuildForMainPlatform()
vm.last_build_lists = []
vm.last_build_lists_filter = { owner: true, status: true, page: 1 }
vm.updateLastBuilds()
init(dataservice)
vm.selectSaveToRepository() if !dataservice.build_list_id
return true

View File

@ -1,156 +0,0 @@
$(document).ready(function() {
var new_form = $('#new_form');
var ownership_btn = $('.btn.ownership');
var perpage_btn = $('.btn.per_page');
// TODO: Refactor this handler!! It's too complicated.
$(document).on('change', '#build_list_save_to_repository_id', function(){
var selected_option = $(this).find("option:selected");
var platform_id = selected_option.attr('platform_id');
var rep_name = selected_option.text().match(/[\w-]+\/([\w-]+)/)[1];
var build_platform = $('#build_for_pl_' + platform_id);
var all_repositories = $('.all_platforms input');
all_repositories.removeAttr('checked');
var auto_create_container = $('#build_list_auto_create_container');
var extra_repos = $('.autocomplete-form.extra_repositories');
updateExtraReposAndBuildLists(platform_id);
updatedDefaultArches(selected_option);
$('.autocomplete-form table tbody').empty();
if (build_platform.size() == 0) {
all_repositories.removeAttr('disabled');
auto_create_container.removeAttr('checked');
addPersonalPlatformToExtraRepos(selected_option, extra_repos);
extra_repos.show();
var version_sel = $('#build_list_project_version').val();
var parent = $('div.build_for_pl').filter(function (){
return $(this).text() == version_sel;
}).parent();
parent.find('input').removeAttr('disabled');
parent.find('input[rep_name="main"]').attr('checked', 'checked');
} else {
all_repositories.attr('disabled', 'disabled');
extra_repos.hide();
var parent = build_platform.parent();
parent.find('input').removeAttr('disabled');
parent.find('input[rep_name="main"]').attr('checked', 'checked');
parent.find('input[rep_name="base"]').attr('checked', 'checked');
if (rep_name != 'main') {
parent.find('input[rep_name="' + rep_name + '"]').attr('checked', 'checked');
}
setBranchSelected(selected_option);
}
var build_list_auto_publish_status = $('#build_list_auto_publish_status');
if (selected_option.attr('publish_without_qa') == '1') {
build_list_auto_publish_status.removeAttr('disabled').val('default');
} else {
build_list_auto_publish_status.val('none').attr('disabled', 'disabled');
auto_create_container.attr('checked', 'checked');
}
});
ownership_btn.click(function() {
ownership_btn.removeClass('active');
$('#filter_ownership').val($(this).val());
$(this).addClass('active');
return false;
});
perpage_btn.click(function() {
perpage_btn.removeClass('active');
$('#per_page').val($(this).val());
$(this).addClass('active');
return false;
});
$('a#updated_at_clear').click(function() {
$($(this).attr('href')).val('');
return false;
});
$('#filter_clear').click(function() {
$('#monitoring_filter .input_cleanse').val('');
$('.btn-group .btn').removeClass('active');
if(ownership_btn.length > 0) { ownership_btn[0].click(); }
perpage_btn[0].click();
return false;
});
$('.mediumheight.min').datepicker({
dateFormat: 'dd/mm/yy',
showButtonPanel: true
});
$(document).on('click', '#owner_filter_build_lists, #status_filter_build_lists', function(){
$('#datatable').dataTable().fnDraw();
});
$(document).on('click', '#clone_build_list', function() {
$.ajax({
type: 'GET',
url: $(this).attr('href') + '&show=inline',
success: function(data){
new_form.html(data);
$(document).scrollTop(new_form.offset().top);
},
error: function(data){
alert('error') // TODO remove
}
});
return false;
});
$(document).on('change', '#build_list_project_version', function(){
var save_to_repo = $('#build_list_save_to_repository_id');
var platform_id = save_to_repo.find("option:selected").attr('platform_id');
var build_platform = $('#build_for_pl_' + platform_id);
if (build_platform.size() == 0) {
save_to_repo.trigger('change');
}
});
});
function updatedDefaultArches(selected_option) {
$('input[name="arches[]"]').removeAttr('checked');
_.each(selected_option.attr('default_arches').split(' '), function(id){
$('#arches_' + id).attr('checked', 'checked');
});
}
function updateExtraReposAndBuildLists(save_to_platform_id) {
$.each($('.autocomplete-form'), function() {
var form = $(this);
var path = form.attr('path') + '?platform_id=' + save_to_platform_id;
form.find('.autocomplete').attr('data-autocomplete', path);
});
}
function addPersonalPlatformToExtraRepos(selected_option, extra_repos) {
var default_value = extra_repos.find('div[label="' + selected_option.text() + '"]');
if (default_value.length == 0) { return; }
addDataToAutocompleteForm(
extra_repos,
default_value.attr('path'),
default_value.attr('label'),
default_value.attr('name'),
default_value.attr('value')
);
}
function setBranchSelected(selected_option) {
var pl_name = selected_option.text().match(/([\w-.]+)\/[\w-.]+/)[1];
var bl_version_sel = $('#build_list_project_version');
var branch_pl_opt = bl_version_sel.find('option[value="' + pl_name + '"]');
// If there is branch we need - set it selected:
if (branch_pl_opt.size() > 0) {
bl_version_sel.find('option[selected]').removeAttr('selected');
branch_pl_opt.attr('selected', 'selected');
bl_version_sel.val(branch_pl_opt);
// hack for FF to force render of select box.
bl_version_sel[0].innerHTML = bl_version_sel[0].innerHTML;
}
}

View File

@ -185,11 +185,12 @@ class Projects::BuildListsController < Projects::BaseController
def list
@build_lists = @project.build_lists
@build_lists = @build_lists.paginate(page: page, per_page: per_page)
@total_build_lists = @build_lists.count
@build_lists = @build_lists.where(user_id: current_user) if params[:owner_filter] == 'true'
@build_lists = @build_lists.where(status: [BuildList::BUILD_ERROR, BuildList::FAILED_PUBLISH, BuildList::REJECTED_PUBLISH]) if params[:status_filter] == 'true'
@build_lists = @build_lists.order("build_lists.updated_at #{sort_dir}")
@total_build_lists = @build_lists.count
@build_lists = @build_lists.recent.paginate(page: current_page)
render partial: 'build_lists_ajax', layout: false
end

View File

@ -106,15 +106,39 @@ module BuildListsHelper
end
end
def build_list_version_link(bl, str_version = false)
def build_list_version_name(bl)
hash_size=5
if bl.commit_hash.present?
if bl.last_published_commit_hash.present? && bl.last_published_commit_hash != bl.commit_hash
"#{shortest_hash_id bl.last_published_commit_hash, hash_size}...#{shortest_hash_id bl.commit_hash, hash_size}"
else
shortest_hash_id(bl.commit_hash, hash_size)
end
else
bl.project_version
end
end
def get_build_list_version_path(bl)
if bl.commit_hash.present?
if bl.last_published_commit_hash.present? && bl.last_published_commit_hash != bl.commit_hash
diff_path(bl.project, bl.last_published_commit_hash) + "...#{bl.commit_hash}"
else
commit_path(bl.project, bl.commit_hash)
end
else
nil
end
end
def build_list_version_link(bl)
hash_size=5
if bl.commit_hash.present?
if bl.last_published_commit_hash.present? && bl.last_published_commit_hash != bl.commit_hash
link_to "#{shortest_hash_id bl.last_published_commit_hash, hash_size}...#{shortest_hash_id bl.commit_hash, hash_size}",
diff_path(bl.project, bl.last_published_commit_hash) + "...#{bl.commit_hash}"
else
link_to str_version ? "#{shortest_hash_id bl.commit_hash, hash_size}" : shortest_hash_id(bl.commit_hash, hash_size),
commit_path(bl.project, bl.commit_hash)
link_to shortest_hash_id(bl.commit_hash, hash_size), commit_path(bl.project, bl.commit_hash)
end
else
bl.project_version
@ -164,6 +188,7 @@ module BuildListsHelper
def new_build_list_data(build_list, project, params)
res = {
build_list_id: params[:build_list_id],
name_with_owner: project.name_with_owner,
build_for_platform_id: params[:build_list].try(:[], :build_for_platform_id),
save_to_repository_id: save_to_repository_id(params),
project_version: project_version(project, params),
@ -176,7 +201,7 @@ module BuildListsHelper
extra_repos: extra_repos(params),
extra_build_lists: extra_build_lists(params),
auto_create_container: default_auto_create_container(params, build_list),
auto_publish_status: params[:build_list][:auto_publish_status]
auto_publish_status: params[:build_list].try(:[], :auto_publish_status)
}
res.to_json
end

View File

@ -6,6 +6,8 @@ class BuildList < ActiveRecord::Base
include BuildListObserver
include EventLoggable
self.per_page = 25
belongs_to :project
belongs_to :arch
belongs_to :save_to_platform, class_name: 'Platform'

View File

@ -1,21 +1,30 @@
build_lists = @build_lists.map do |build_list|
build_for = " (#{build_list.build_for_platform.name})" if build_list.build_for_platform && build_list.save_to_platform.personal?
[
[link_to(build_list.id, build_list),
link_to(t('layout.clone'), new_project_build_list_path(@project, build_list_id: build_list.id),
id: 'clone_build_list')
].join('<br/>').html_safe,
build_list.human_status,
build_list_version_link(build_list),
get_version_release(build_list),
link_to("#{build_list.save_to_platform.name}/#{build_list.save_to_repository.name}#{build_for}", [build_list.save_to_platform, build_list.save_to_repository]),
build_list.arch.try(:name) || t('layout.arches.unexisted_arch'),
link_to(build_list.user.try(:fullname), build_list.user),
datetime_moment(build_list.updated_at).html_safe
]
json.build_lists @build_lists do |bl|
json.id bl.id
json.path build_list_path(bl)
json.human_status bl.human_status
json.version do
json.name build_list_version_name(bl)
json.path get_build_list_version_path(bl)
json.release get_version_release(bl)
end
if bl.build_for_platform && bl.save_to_platform.personal?
build_for = " (#{bl.build_for_platform.name})"
end
json.save_to_repository do
json.path platform_repository_path(bl.save_to_platform, bl.save_to_repository)
json.name "#{bl.save_to_platform.name}/#{bl.save_to_repository.name}#{build_for}"
end
json.arch bl.arch.try(:name) || t('layout.arches.unexisted_arch')
json.user do
json.path user_path(bl.user) if bl.user
json.fullname bl.user.try(:fullname)
end
json.updated_at bl.updated_at
end
json.sEcho params[:sEcho].to_i || -1
json.iTotalRecords @total_build_lists
json.iTotalDisplayRecords @build_lists.count
json.aaData build_lists
json.total_items @total_build_lists

View File

@ -1,41 +0,0 @@
.all
%h3= t 'layout.build_lists.last_build_lists'
%h4= t 'layout.relations.filters'
.checkbox
%label
= check_box_tag :owner_filter_build_lists, true, (params[:owner_filter] || 'true') == 'true',
class: 'form-control'
= t 'layout.build_lists.only_my_build_lists'
.both
= check_box_tag :status_filter_build_lists, true, (params[:status_filter] || 'true') == 'true'
= label_tag t('layout.build_lists.failed_build_lists')
- columns, default_column = [], {type: 'html', sortable: false, searchable: false}
- 8.times { columns << default_column }
= raw datatable(columns, {sort_by: "[7, 'asc']", processing: t('layout.processing'), search: 'false',
pagination_labels: {previous: t('datatables.previous_label'), next: t('datatables.next_label')},
empty_label: t('datatables.empty_label'),
info_label: t('datatables.info_label'),
info_empty_label: t('datatables.info_empty_label'),
filtered_label: t('datatables.filtered_label'),
table_dom_id: 'datatable',
auto_width: 'false',
ajax_source: "#{url_for controller: 'projects/build_lists', action: :list}",
additional_data: {owner_filter: "' + $('#owner_filter_build_lists:checked').val() + '",
status_filter: "' + $('#status_filter_build_lists:checked').val() + '"} })
%table#datatable.tablesorter.list-users{cellspacing: 0, cellpadding: 0}
%thead
%tr
%th.th1= t('activerecord.attributes.build_list.id')
%th.th2= t('activerecord.attributes.build_list.status')
%th.th2= t('diff')
%th.th2= t('activerecord.attributes.build_list.project_version')
%th.th2= t('activerecord.attributes.build_list.save_to_repository')
%th.th1= t('activerecord.attributes.build_list.arch_short')
%th.th2= t('activerecord.attributes.build_list.user')
%th.th1= t('activerecord.attributes.build_list.updated_at')
%tbody
%br

View File

@ -2,5 +2,5 @@
.container{ 'ng-controller' => 'NewBuildListController as newBuildCtrl', 'ng-cloak' => true }
#new_form= render 'projects/build_lists/new_build/new_form', project: @project, build_list: @build_list
%br
=# render 'last_build_lists', project: @project
= render 'projects/build_lists/new_build/last_build_lists', project: @project
= render 'projects/base/submenu'

View File

@ -10,7 +10,7 @@ div[ ng-hide = "#{field == :ExtraRepositories ? "newBuildCtrl.is_build_for_main_
a<[ class='fa fa-question-circle' href='#' data-toggle='modal' data-target="##{modal_id}" ]
.modal.fade[ id=modal_id tabindex='-1' role='dialog'
aria-labelledby="#{modal_id}Label" aria-hidden='true' ]
aria-labelledby="#{modal_id}Label" aria-hidden='true' ]
.modal-dialog
.modal-content
.modal-header

View File

@ -0,0 +1,50 @@
h3= t 'layout.build_lists.last_build_lists'
h4= t 'layout.relations.filters'
.checkbox
label
= check_box_tag :owner_filter_build_lists, true,
(params[:owner_filter] || 'true') == 'true',
'ng-click' => 'newBuildCtrl.updateFilterOwner()',
'ng-value' => 'newBuildCtrl.last_builds_filter.owner'
= t 'layout.build_lists.only_my_build_lists'
.checkbox
label
= check_box_tag :status_filter_build_lists, true,
(params[:status_filter] || 'true') == 'true',
'ng-value' => 'newBuildCtrl.last_builds_filter.status',
'ng-click' => 'newBuildCtrl.updateFilterStatus()'
= t 'layout.build_lists.failed_build_lists'
table.table
thead
tr
th= t('activerecord.attributes.build_list.id')
th= t('activerecord.attributes.build_list.status')
th= t('diff')
th= t('activerecord.attributes.build_list.project_version')
th= t('activerecord.attributes.build_list.save_to_repository')
th= t('activerecord.attributes.build_list.arch_short')
th= t('activerecord.attributes.build_list.user')
th= t('activerecord.attributes.build_list.updated_at')
tbody
tr[ ng-repeat = 'last in newBuildCtrl.last_build_lists' ]
td
a[ ng-href = '{{ last.path }}' ] {{ last.id }}
br
a[ ng-click = 'cloneBuildList(last.id)' ]= t 'layout.clone'
td[] {{ last.human_status }}
td
a[ ng-href = '{{ last.version.path }}' ] {{ last.version.name }}
td[] {{ last.version.release }}
td
a[ ng-href = '{{ last.save_to_repository.path }}' ] {{ last.save_to_repository.name }}
td[] {{ last.arch }}
td
a[ ng-href = '{{ last.user.path }}' ] {{ last.user.fullname }}
td
span[ am-time-ago = 'last.updated_at'
title = "{{ last.updated_at | amDateFormat:'ddd, LLL' }}" ]
= angularjs_paginate( per_page: BuildList.per_page )

View File

@ -8,14 +8,16 @@
%select.form-control.boffset20{ 'ng-model' => 'newBuildCtrl.save_to_repository',
'ng-options' => 'r.name for r in newBuildCtrl.save_to_repositories track by r.id',
'ng-change' => 'newBuildCtrl.selectSaveToRepository()',
name: 'build_list[save_to_repository_id]' }
name: 'build_list[save_to_repository_id]',
required: true }
%h4= t 'activerecord.attributes.build_list.project_version'
%select.form-control.boffset20{ 'ng-model' => 'newBuildCtrl.project_version',
'ng-options' => 'v.name group by v.kind for v in newBuildCtrl.project_versions track by v.name',
'ng-change' => 'newBuildCtrl.selectProjectVersion()',
'ng-value' => 'newBuildCtrl.project_version',
name: 'build_list[project_version]' }
name: 'build_list[project_version]',
required: true }
%h4= t 'activerecord.attributes.build_list.arch'
.checkbox{ 'ng-repeat' => 'arch in newBuildCtrl.arches' }