GordonDiggs/cataloguais

View on GitHub
views/index.haml

Summary

Maintainability
Test Coverage
.content
  - if session['editing_enabled']
    #add-new
      %form.ajax{ :action => '/new', :method => 'post' }
        - settings.fields.each do |field|
          %input{ :type => 'text', :name => "item[#{field.robotize}]", :placeholder => field, :style => "width:#{(0.8/settings.fields.count)*100}%" }
        %input{ :type => 'submit', :value => 'Add' }

  %table{ :cellspacing => 0 }
    %tr
      - @fields.each do |field|
        %th
          - next_direction = (@sort[0].gsub(/created_at/, 'added_on') == field.robotize) ? opposite_direction : :asc
          %a{ :href => "/?sort=#{field.robotize}&direction=#{next_direction}&search=#{params[:search]}" }= field
          - if @sort[0].gsub(/created_at/, 'added_on') == field.robotize
            %span= (@direction == :asc) ? "\u2191" : "\u2193"
    - @items.each do |item|
      = item_table_row(item)

- if ENV['ADMIN_PASSWORD']
  #editing-bar
    %span== #{@items.count} items.
    %a{ :href => '/graphs' } stats
    %a.export{ :href => '/export' } export all items to csv
    %a.random{ :href => 'javascript:' } random
    - if session['editing_enabled']
      %a.logout{ :href => '/logout' } disable editing
      %a.import{ :href => '' } import csv
      %form{ :action => '/import', :method => 'post', :enctype => 'multipart/form-data'}
        %input{ :type => 'file', :name => 'file' }
        %input{ :type => 'submit', :value => 'Import' }
    - else
      editing is disabled.
      %a.login{ :href => '' } enable now?
      %form{ :action => '/login', :method => 'post' }
        %input{ :type => 'password', :name => 'password', :placeholder => 'Password' }
        %input{ :type => 'submit', :value => 'Enable' }
    %form.search{ :action => '/', :method => 'get' }
      %input{ :type => 'text', :name => 'search', :placeholder => 'Search', :value => params[:search] }
  .toggle-controls
    %a{ :href => '' } hide controls