Skip to content

Commit

Permalink
Merge pull request #968 from mdeniz/master
Browse files Browse the repository at this point in the history
[webui] Added a tab with the last requests at user's home
  • Loading branch information
hennevogel committed Jul 21, 2015
2 parents bafe316 + 1b176fc commit d7277e4
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 95 deletions.
9 changes: 5 additions & 4 deletions src/api/app/assets/javascripts/webui/bratwurst.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ $(function() {
$('a[data-toggle="tab"]').on('click', function(e) {
history.pushState(null, null, $(this).attr('href'));
});

// navigate to a tab when the history changes
window.addEventListener("popstate", function(e) {
var activeTab = $('[href=' + location.hash + ']');
var activeTab = $('[href=' + location.hash + ']');
window.addEventListener('popstate', function(e) {
if (activeTab.length) {
activeTab.tab('show');
} else {
Expand All @@ -31,6 +32,6 @@ $(function() {
});

$(function() {
var hash = window.location.hash;
hash && $('ul.nav a[href="' + hash + '"]').tab('show');
var hash = window.location.hash;
hash && $('ul.nav a[href="' + hash + '"]').tab('show');
});
28 changes: 14 additions & 14 deletions src/api/app/assets/stylesheets/webui/application/style.css.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
**
** Funktion: Provides all styles for build.openSUSE.org
** Author: Frank Sundermeyer <fs@opensuse.org>, Robert Lihm <rlihm@opensuse.org>
Expand Down Expand Up @@ -198,15 +198,15 @@ div#log_space_wrapper {
position: relative;
}
.flagimage:hover {
z-index:25;
z-index:25;

div.flagtoggle {
display: block;
background: white;
border: 1px solid black;
border: 1px solid black;
position:absolute;
top:10px;
left:5ex;
top:10px;
left:5ex;
padding: 5px;
text-align: left;

Expand All @@ -220,7 +220,7 @@ div#log_space_wrapper {
left: 0px;
}

a {
a {
margin-left: 30px;
min-height: 27px;
display: block;
Expand All @@ -244,15 +244,15 @@ div#log_space_wrapper {

table.patchinfo td { vertical-align: middle; }

.flot_legend table {
.flot_legend table {
display: inline;
}

.y1Axis .tickLabel {
.y1Axis .tickLabel {
min-width: 15px;
}

.plotspinner {
.plotspinner {
position: absolute;
right: 40px;
top: 20px;
Expand All @@ -278,7 +278,7 @@ table.patchinfo td { vertical-align: middle; }
vertical-align: middle;
}
}
}
}

.horizontal-list:after {
content: ".";
Expand Down Expand Up @@ -335,7 +335,7 @@ div.dataTables_wrapper:after {

.attribute-values {
form,div {
display: inline;
display: inline;
}
}

Expand All @@ -350,11 +350,11 @@ div.dataTables_wrapper:after {
float: left;
margin-right: 5px;
}

/*
.dataTable th.sorting_disabled { display: none; }

*/
.global-navigation-menu li span.global-navigation-icon {
background-image: image-url("globalnav-im.png");
background-image: image-url("globalnav-im.png");
}

.global-navigation-menu.global-navigation-menu-favorites li span.icons-project {
Expand Down
44 changes: 26 additions & 18 deletions src/api/app/controllers/webui/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ class Webui::UserController < Webui::WebuiController
:lock, :admin, :login, :notifications, :update_notifications, :show]
before_filter :check_display_user, :only => [:show, :edit, :requests, :list_my, :delete, :save, :confirm, :admin, :lock]
before_filter :require_login, :only => [:edit, :save, :notifications, :update_notifications]
# before_filter :require_login, :except => [:login, :do_login, :home, :requests, :render_requests_json, :user_icon, :icon, :register, :register_dialog, :autocomplete, :tokens, :list_users]
before_filter :require_admin, :only => [:edit, :delete, :lock, :confirm, :admin]

skip_before_action :check_anonymous, only: [:do_login]

def logout
Expand Down Expand Up @@ -71,6 +70,7 @@ def show
@requests_in = @displayed_user.incoming_requests
@requests_out = @displayed_user.outgouing_requests
@declined_requests = @displayed_user.declined_requests
@user_have_requests = @displayed_user.requests?
end
end

Expand All @@ -82,25 +82,33 @@ def home
end
end

# Request from the user
def requests
session[:requests] = @displayed_user.declined_requests.pluck(:id) + @displayed_user.involved_reviews.map { |r| r.id } + @displayed_user.incoming_requests.pluck(:id)
@requests = @displayed_user.declined_requests + @displayed_user.involved_reviews + @displayed_user.incoming_requests
@default_request_type = params[:type] if params[:type]
@default_request_state = params[:state] if params[:state]
sortable_fields = {
0 => :created_at,
3 => :creator,
5 => :priority
}
sorting_field = sortable_fields[params[:iSortCol_0].to_i]
sorting_field ||= :created_at
@requests = @displayed_user.requests(params[:sSearch])
@requests_count = @requests.clone.count
@requests = @requests.offset(params[:iDisplayStart].to_i).limit(params[:iDisplayLength].to_i).reorder(sorting_field => params[:sSortDir_0].to_sym)
respond_to do |format|
format.json { render_requests_json }
# For jquery dataTable
format.json {
render_json_response_for_dataTable(
echo_next_count: params[:sEcho].to_i + 1,
total_records_count: @displayed_user.requests.count,
total_filtered_records_count: @requests_count,
records: @requests
) do |request|
render_to_string(:partial => "shared/single_request.json", locals: { req: request, no_target: true, hide_state: true }).to_s.split(',')
end
}
end
end

def render_requests_json
rawdata = Hash.new
rawdata['review'] = @displayed_user.involved_reviews.to_a
rawdata['new'] = @displayed_user.incoming_requests.to_a
rawdata['declined'] = @displayed_user.declined_requests.to_a
rawdata['patchinfos'] = @displayed_user.involved_patchinfos.to_a
render json: Yajl::Encoder.encode(rawdata)
end

def save
unless User.current.is_admin?
if User.current != @displayed_user
Expand Down Expand Up @@ -189,7 +197,7 @@ def register
end

flash[:success] = "The account \"#{params[:login]}\" is now active."

if User.current.is_admin?
redirect_to :controller => :configuration, :action => :users
else
Expand All @@ -208,7 +216,7 @@ def password_dialog
end

def change_password
# check the valid of the params
# check the valid of the params
if not params[:password] == session[:password]
errmsg = 'The value of current password does not match your current password. Please enter the password and try again.'
end
Expand Down
26 changes: 23 additions & 3 deletions src/api/app/controllers/webui/webui_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def handle_unverified_request
end
end
end

rescue_from ActionController::RedirectBackError do |exception|
redirect_to root_path
end
Expand Down Expand Up @@ -124,6 +124,26 @@ def redirect_back_or_to(options = {}, response_status = {})
end
end

# Renders a json response for jquery dataTables
def render_json_response_for_dataTable(options)
options[:echo_next_count] ||= 1
options[:total_records_count] ||= 0
options[:total_displayed_records] ||= 0
response = {
sEcho: options[:echo_next_count].to_i + 1,
iTotalRecords: options[:total_records_count].to_i,
iTotalDisplayRecords: options[:total_filtered_records_count].to_i,
aaData: options[:records].map do |record|
if block_given?
yield record
else
record
end
end
}
render json: Yajl::Encoder.encode(response)
end

def require_login
if User.current.is_nobody?
render :text => 'Please login' and return false if request.xhr?
Expand Down Expand Up @@ -162,7 +182,7 @@ def authenticate_proxy
if mode == :simulate
proxy_user ||= CONFIG['proxy_auth_test_user'] || CONFIG['proxy_test_user']
proxy_email ||= CONFIG['proxy_auth_test_email']
end
end
if proxy_user
session[:login] = proxy_user
session[:email] = proxy_email
Expand Down Expand Up @@ -272,7 +292,7 @@ def map_to_workers(arch)
else arch
end
end

private

def put_body_to_tempfile(xmlbody)
Expand Down
28 changes: 17 additions & 11 deletions src/api/app/models/bs_request_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@ def initialize(opts)
wrapper_for_inner_or { extend_query_for_project }
end

if opts[:user]
wrapper_for_inner_or { extend_query_for_user(opts[:user]) }
end

if opts[:group]
wrapper_for_inner_or { extend_query_for_group(opts[:group]) }
end

if opts[:ids]
@rel = @rel.where(id: opts[:ids])
end
wrapper_for_inner_or { extend_query_for_user(opts[:user]) } if opts[:user]

wrapper_for_inner_or { extend_query_for_group(opts[:group]) } if opts[:group]

@rel = @rel.where(id: opts[:ids]) if opts[:ids]

# Searching capabilities using dataTable (1.9)
searchable_fields = [
'bs_requests.creator',
'bs_requests.priority',
'bs_request_actions.target_project',
'bs_request_actions.source_project',
'bs_request_actions.type'
]
bind_search = ["%#{opts[:search]}%"] * searchable_fields.length
@rel = @rel.where([searchable_fields.map { |field| "#{field} like ?" }.join(' or '),
bind_search].flatten) if opts[:search]
end

def ids
Expand Down
Loading

0 comments on commit d7277e4

Please sign in to comment.