Changeset 715

Show
Ignore:
Timestamp:
11/02/07 17:49:45 (1 year ago)
Author:
markku
Message:

Closes #484

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/application.rb

    r710 r715  
    2020 
    2121  layout 'mainlevel' 
    22   before_filter :set_current_user, :set_selected_asset, :prepare_tree_view, :protect_page_groups, :handle_cancel_submit, :set_host 
     22  before_filter :set_current_user, :set_selected_asset, :prepare_tree_view, :protect_page_groups, :handle_cancel_submit, :set_host, :check_new_service_requests 
    2323  after_filter :reset_timedout_session, :process_model_events 
    2424 
     
    206206    login = session[:user].login if session[:user] 
    207207    ActiveRecord::Base.logged_information(login, request.remote_ip) 
    208     if UserAccount.current_user.is_a?(User) 
    209       @message_count = session[:user].received_messages.count(:conditions => "unread = '1'"
    210       @message_id = session[:user].received_messages.find(:first, :conditions => "unread = '1'").id if @message_count == 1 
     208    if UserAccount.current_user.instance_of?(User) 
     209      @message_count = session[:user].received_messages.count(:conditions => ['unread = ?', true]
     210      @message_id = session[:user].received_messages.find(:first, :conditions => ['unread = ?', true]).id if @message_count == 1 
    211211    end 
    212212    GetText.locale = session[:user].lang 
     
    681681  end 
    682682 
     683  # Function: check_new_service_requests 
     684  # ==================================== 
     685  # Checks for new service requests by counting them. 
     686  # 
     687  def check_new_service_requests 
     688    conditions = ['task_type_id = ? AND state = ?', TaskType.get_service_request_type.id, Task.NEW] 
     689    @service_request_count = Task.count_authorized_to(:read, conditions) 
     690    @service_request_id = Task.find_authorized_to_read(:first, :conditions => conditions).id if @service_request_count == 1 
     691  end 
    683692end 
  • trunk/app/controllers/task_controller.rb

    r710 r715  
    389389  # Method: list_service_requests 
    390390  # ============================= 
    391   # Shows a list of service requests task 
     391  # Shows a list of service request tasks 
    392392  # 
    393393  def list_service_requests 
    394     define_priority_options 
    395     @fields = [ 
    396                 [_('ID'), :self, 'id'], 
    397                 [_('State'), {:name => :state}.merge(@state_to_text), 'state'], 
    398                 [_('Description'), :short_description, 'short_description'], 
    399                 [_('Created at'), :created_at, 'created_at'], 
    400                 [_('Asset'), :asset, 'asset_id'] 
    401               ] 
    402  
    403     asset_options = Asset.find_authorized_to(:create_task, [:all]).collect { |a| [a.full_code, a.id] } 
    404     @actions = [] 
    405     @check_title = _('Select') 
    406     @list_actions =  [ 
    407                   { :name => _('Remove'), :url => {:action => 'remove'} }, 
    408                   { :name => _('Move'), :url => {:action => 'move'}, 
    409                     :fields => [ [_('Asset'), :our_select_tag, 'asset_id', asset_options] ] } 
    410                 ] 
     394    setup_service_request_list 
    411395 
    412396    if session[:select_branches] 
     
    422406 
    423407    @items = items_for_page(Task, :finder_method => :find_authorized_to_read, :conditions => conditions, :readonly => true) 
     408    common_list 
     409  end 
     410 
     411  # Method: list_new_service_requests 
     412  # ================================== 
     413  # Shows a list of new service request tasks in all assets. 
     414  # 
     415  def list_new_service_requests 
     416    setup_service_request_list 
     417    @title = _('New service requests') 
     418    @hide_subaction_links = true 
     419 
     420    @items = items_for_page(Task, :finder_method => :find_authorized_to_read, 
     421                            :conditions => ['task_type_id = ? AND state = ?', TaskType.get_service_request_type.id, Task.NEW], 
     422                            :readonly => true) 
    424423    common_list 
    425424  end 
     
    452451    @state_to_text = {0 => _('New'), 1 => _('Assigned'), 2 =>  _('Accepted'), 3 => _('Closed')} 
    453452  end 
     453 
     454  def setup_service_request_list 
     455    define_priority_options 
     456    @fields = [ 
     457                [_('ID'), :self, 'id'], 
     458                [_('State'), {:name => :state}.merge(@state_to_text), 'state'], 
     459                [_('Description'), :short_description, 'short_description'], 
     460                [_('Created at'), :created_at, 'created_at'], 
     461                [_('Asset'), :asset, 'asset_id'] 
     462              ] 
     463 
     464    asset_options = Asset.find_authorized_to(:create_task, [:all]).collect { |a| [a.full_code, a.id] } 
     465    @actions = [] 
     466    @check_title = _('Select') 
     467    @list_actions =  [ 
     468                  { :name => _('Remove'), :url => {:action => 'remove'} }, 
     469                  { :name => _('Move'), :url => {:action => 'move'}, 
     470                    :fields => [ [_('Asset'), :our_select_tag, 'asset_id', asset_options] ] } 
     471                ] 
     472  end 
    454473end 
  • trunk/app/views/layouts/mainlevel.rhtml

    r704 r715  
    267267      <% end -%> 
    268268 
     269      <% if @service_request_count == 1 and not (controller.controller_name == 'task' and controller.action_name == 'view' and params.has_key?(:id) and params[:id].to_i == @service_request_id) -%> 
     270        <p id="service_request_count"> 
     271          <%= link_to(_('There is a new service request'), :controller => 'task', :action => 'view', :id => @service_request_id) %> 
     272        </p> 
     273      <% elsif @service_request_count > 1 and controller.action_name != 'list_new_service_requests' -%> 
     274        <p id="service_request_count"> 
     275          <%= link_to(_('There are %i new service requests', @service_request_count), :controller => 'task', :action => 'list_new_service_requests') %> 
     276        </p> 
     277        <% end -%> 
     278 
    269279        <%= @content_for_layout %> 
    270280      </div> 
  • trunk/config/menu.rb

    r710 r715  
    4848                    Page.new('task', 'edit'), 
    4949                    Page.new('task', 'view'), 
    50                     Page.new('task', 'select_asset') 
     50                    Page.new('task', 'select_asset'), 
     51                    Page.new('task', 'list_new_service_requests') 
    5152                  ), 
    5253                  MenuButton.new(_('Timeline'), '22x22/menu_clock.gif', 
  • trunk/db/migrate/010_customer_interface_data.rb

    r712 r715  
    2121    # The new 'task/list_service_requests' key is added to all keyrings 
    2222    # which have the 'task/list' key. 
    23     new_list_key = TempActionKey.create!(:name => 'task/list_service_requests') 
     23    new_list_keys = [ 
     24                     'task/list_service_requests', 
     25                     'task/list_new_service_requests' 
     26                    ].map { |name| TempActionKey.create!(:name => name) } 
    2427    old_list_key = TempActionKey.find_by_name('task/list') 
    2528    if old_list_key 
     
    2730      unless keyring_ids.empty? 
    2831        TempKeyring.find(keyring_ids).each { |keyring| 
    29           puts "Adding the 'task/list_service_requests' action key for '%s'" % keyring.name 
    30           keyring.grant(new_list_key) 
     32          puts "Adding the service request listing keys for '%s'" % keyring.name 
     33          new_list_keys.each { |key| keyring.grant(key) } 
    3134        } 
    3235      end 
  • trunk/public/stylesheets/typography.css

    r602 r715  
    88 
    99h1, h2, h3, h4, h5, h6 { 
    10        font-family: Arial, Verdana, sans-serif; 
    11        color: #467; 
     10        font-family: Arial, Verdana, sans-serif; 
     11        color: #467; 
    1212} 
    1313 
    1414h2 { 
    15        font-size: 1.8em; 
    16        font-weight: bold; 
    17        margin-bottom: 1.6em; 
    18        padding-bottom: 4px; 
    19        border-bottom: 1px solid #CCC; 
     15        font-size: 1.8em; 
     16        font-weight: bold; 
     17        margin-bottom: 1.6em; 
     18        padding-bottom: 4px; 
     19        border-bottom: 1px solid #CCC; 
    2020} 
    2121 
    2222h3 { 
    23        font-size: 1.4em; 
    24        font-weight: bold; 
    25        margin-bottom: .8em; 
    26        padding-bottom: 4px; 
    27        border-bottom: 1px solid #CCC; 
     23        font-size: 1.4em; 
     24        font-weight: bold; 
     25        margin-bottom: .8em; 
     26        padding-bottom: 4px; 
     27        border-bottom: 1px solid #CCC; 
    2828} 
    2929 
    3030h4 { 
    31        font-size: 1.1em; 
    32        font-weight: bold; 
    33        margin-bottom: .8em; 
     31        font-size: 1.1em; 
     32        font-weight: bold; 
     33        margin-bottom: .8em; 
    3434} 
    3535 
     
    3737 
    3838p { 
    39        font-family: Verdana, Arial, sans-serif; 
    40        color: #000; 
    41        margin-bottom: 1.5em; 
    42        
     39        font-family: Verdana, Arial, sans-serif; 
     40        color: #000; 
     41        margin-bottom: 1.5em; 
     42       
    4343 
    4444/* BASE LINK STYLES */ 
     
    4848a:active, 
    4949a:visited { 
    50        color: #45F; 
    51        text-decoration: none; 
     50        color: #45F; 
     51        text-decoration: none; 
    5252} 
    5353 
    5454a:hover { 
    55        text-decoration: underline; 
     55        text-decoration: underline; 
    5656} 
    5757 
     
    6464 
    6565ul, ol, dl { 
    66        margin-bottom: 1.5em; 
    67        padding: 0; 
     66        margin-bottom: 1.5em; 
     67        padding: 0; 
    6868} 
    6969 
    7070ul, ol { 
    71        margin-left: 2em; 
    72        list-style-position: outside; 
     71        margin-left: 2em; 
     72        list-style-position: outside; 
    7373} 
    7474 
     
    7777 
    7878ul li, ol li { 
    79        line-height: 1.6em; 
     79        line-height: 1.6em; 
    8080} 
    8181 
    8282dt { 
    83        font-weight: bold; 
     83        font-weight: bold; 
    8484} 
    8585 
    8686dt.sub { 
    87        font-weight: normal; 
    88        text-decoration: underline; 
     87        font-weight: normal; 
     88        text-decoration: underline; 
    8989} 
    9090 
    9191dd { 
    92        margin-left: 2em; 
     92        margin-left: 2em; 
    9393} 
    9494 
    9595/* BASE TABLE STYLES */ 
    96 /* This needs a complete rework and cleanup, custom tables should be moved under  
     96/* This needs a complete rework and cleanup, custom tables should be moved under 
    9797   their section sheets and a base table design needs to be written */ 
    9898 
    9999table { 
    100        margin-bottom: 1em; 
    101        border-spacing: 0; 
    102        width: 100%; 
     100        margin-bottom: 1em; 
     101        border-spacing: 0; 
     102        width: 100%; 
    103103} 
    104104 
    105105th { 
    106        font-weight: bold; 
    107        padding: 0.3em 1.5em 0.3em 0.4em; 
    108        text-align: left; 
     106        font-weight: bold; 
     107        padding: 0.3em 1.5em 0.3em 0.4em; 
     108        text-align: left; 
    109109} 
    110110 
    111111td { 
    112        padding: 0.3em 1.5em 0.3em 0.4em; 
     112        padding: 0.3em 1.5em 0.3em 0.4em; 
    113113} 
    114114 
    115115table.form td, table.form th { 
    116        border-bottom: 1px solid #EEE; 
    117        padding: 7px 0; 
     116        border-bottom: 1px solid #EEE; 
     117        padding: 7px 0; 
    118118} 
    119119 
    120120table.form th { 
    121        padding-left: .8em; 
     121        padding-left: .8em; 
    122122} 
    123123 
    124124table.form th.light { 
    125        font-weight: normal; 
     125        font-weight: normal; 
    126126} 
    127127 
    128128table.form td { 
    129        padding-left: .8em; 
    130        padding-right: .8em; 
     129        padding-left: .8em; 
     130        padding-right: .8em; 
    131131} 
    132132 
    133133table.buttons { 
    134        border: 1px solid #CCC; 
    135        background: #FFF url(/images/bg_table_form_buttons.gif) top left repeat-x; 
    136        margin-bottom: 2em; 
     134        border: 1px solid #CCC; 
     135        background: #FFF url(/images/bg_table_form_buttons.gif) top left repeat-x; 
     136        margin-bottom: 2em; 
    137137} 
    138138 
    139139table.buttons td, table.buttons th { 
    140        padding: 5px 10px; 
     140        padding: 5px 10px; 
    141141} 
    142142 
     
    273273/* FORM STYLES */ 
    274274 
    275 form {  
    276        margin-bottom: 1em; 
     275form { 
     276        margin-bottom: 1em; 
    277277} 
    278278 
    279279form#cancel { 
    280        float: left; 
     280        float: left; 
    281281} 
    282282 
     
    302302 
    303303#notice { 
    304        background: #def1ce url(../images/info.png) 5px 5px no-repeat; 
    305        padding: 1em 1em 1em 4em; 
    306        line-height: 1em; 
    307        margin-bottom: 2em; 
     304        background: #def1ce url(../images/info.png) 5px 5px no-repeat; 
     305        padding: 1em 1em 1em 4em; 
     306        line-height: 1em; 
     307        margin-bottom: 2em; 
    308308} 
    309309 
    310310#error { 
    311        background: #f1cece url(../images/error.png) 5px 5px no-repeat; 
    312        padding: 1em 1em 1em 4em; 
    313        line-height: 1em; 
    314        margin-bottom: 2em; 
     311        background: #f1cece url(../images/error.png) 5px 5px no-repeat; 
     312        padding: 1em 1em 1em 4em; 
     313        line-height: 1em; 
     314        margin-bottom: 2em; 
    315315} 
    316316 
    317317#message_count { 
    318         background: #dddddd url(../images/22x22/message.png) 5px 5px no-repeat; 
    319         padding: 1em 1em 1em 4em; 
    320         line-height: 1em; 
    321         margin-bottom: 2em; 
     318        background: #dddddd url(../images/22x22/message.png) 5px 5px no-repeat; 
     319        padding: 1em 1em 1em 4em; 
     320        line-height: 1em; 
     321        margin-bottom: 2em; 
     322
     323 
     324#service_request_count { 
     325        background: #ffa url(../images/22x22/task.png) 5px 5px no-repeat; 
     326        padding: 1em 1em 1em 4em; 
     327        line-height: 1em; 
     328        margin-bottom: 2em; 
    322329} 
    323330 
    324331div.errorExplanation p, div.errorExplanation ul { /* Validation errors */ 
    325        margin: 0em; 
     332        margin: 0em; 
    326333} 
    327334 
    328335div.errorExplanation { 
    329  /*    border: 1px solid black;*/ 
    330        background: #f1cece url(../images/error.png) 5px 5px no-repeat; 
    331        padding: 1em 1em 1em 4em; 
    332        line-height: 1em; 
    333        margin-bottom: 2em; 
     336 /*     border: 1px solid black;*/ 
     337        background: #f1cece url(../images/error.png) 5px 5px no-repeat; 
     338        padding: 1em 1em 1em 4em; 
     339        line-height: 1em; 
     340        margin-bottom: 2em; 
    334341} 
    335342 
     
    342349 
    343350div.fieldWithErrors input { 
    344        background-color: #f1cece; 
     351        background-color: #f1cece; 
    345352} 
    346353 
    347354input.error { 
    348        background-color: #f1cece; 
     355        background-color: #f1cece; 
    349356} 
    350357 
    351358#table-form-buttons { 
    352        text-align: right; 
    353        border: 1px solid #CCC; 
    354        padding: 5px 10px; 
    355        margin-bottom: 2em; 
    356        background: #FFF url(/images/bg_table_form_buttons.gif) top left repeat-x; 
     359        text-align: right; 
     360        border: 1px solid #CCC; 
     361        padding: 5px 10px; 
     362        margin-bottom: 2em; 
     363        background: #FFF url(/images/bg_table_form_buttons.gif) top left repeat-x; 
    357364} 
    358365 
    359366/* SEARCH BOX (hidden) */ 
    360367div#search_box { 
    361        display: none; 
     368        display: none; 
    362369    visibility: hidden; /* FIXME: Find a better location */ 
    363370} 
  • trunk/test/functional/task_controller_test.rb

    r710 r715  
    344344  end 
    345345 
     346  def test_list_new_service_request_GET_empty 
     347    @keyring.action_keys << create_action_key('task/list_new_service_requests') 
     348    login('test') 
     349 
     350    customer = create_customer('customer') 
     351    UserAccount.current_user = @user 
     352    assert @root.update_attribute(:customer, customer) 
     353 
     354    UserAccount.current_user = customer 
     355    create_task_in_state(Task.ACCEPTED) 
     356    create_task_in_state(Task.ASSIGNED) 
     357    create_task_in_state(Task.CLOSED) 
     358 
     359    get 'list_new_service_requests' 
     360    assert_response :success 
     361    assert_template 'shared/_list_items' 
     362    assert_equal true, assigns(:items).empty? 
     363  end 
     364 
     365  def test_list_new_service_request_GET_not_empty 
     366    @keyring.action_keys << create_action_key('task/list_new_service_requests') 
     367 
     368    customer = create_customer('customer') 
     369    UserAccount.current_user = @user 
     370    assert @root.update_attribute(:customer, customer) 
     371 
     372    UserAccount.current_user = customer 
     373    for i in 1..100 
     374      create_task(@root, true, 'Service request %d' % i) 
     375    end 
     376 
     377    login('test') 
     378 
     379    get 'list_new_service_requests' 
     380    assert_response :success 
     381    assert_template 'shared/_list_items' 
     382    assert_equal false, assigns(:items).empty? 
     383  end 
     384 
    346385  private 
    347386 

© 2004-2007 Norfello Oy All Rights Reserved