thegreatape/literate-minuteman

View on GitHub
app/views/books/index.html.haml

Summary

Maintainability
Test Coverage
.books{"ng-controller" => "BooksCtrl"}
  .loading{'ng-hide' => 'books.$resolved'}
    .progress.progress-striped.active
      .progress-bar.progress-bar-info{"style"=>"width: 100%"}
        Loading...

  .pending.panel.panel-info{'ng-show' => 'books.$resolved && pendingBookCount > 0'}
    .panel-heading
      Loading New Books
    .panel-body
      %p Our gruff-but-friendly robot army is currently fetching your books. New books will appear below when they're found at your selected libraries. This will take a while the first time, so go grab a beverage and a book!
      .container
        .row
          .col-lg-2.col-sm-3.col-xs-5.text-right {{pendingBookCount}} books to go.
          .col-lg-9.col-sm-7.col-xs-5
            .progress.progress-striped.active
              .progress-bar.progress-bar-info{role: "progressbar", "aria-valuenow" => "{{pendingBookCount}}", "aria-valuemin"=>"0", "aria-valuemax"=>"{{books.length}}", "style"=>"width: {{100 - (pendingBookCount / books.length * 100)}}%"}

  .filter{'ng-show' => 'books.$resolved'}
    = render 'filter_form'


  .book-result{'ng-repeat' => 'book in books | filter:bookFilter'}
    .row.book-data
      .col-lg-1.col-md-1.col-sm-2.col-xs-3
        %a{href: "{{book.goodreads_link}}"}
          %img.book-image{"ng-src" => "{{ book.image_url }}"}
      .col-lg-11.col-md-11.col-sm-10.col-xs-9
        %a.title{href: "{{book.goodreads_link}}"}
          {{ book.title }}
        .author
          {{ book.author }}
        %a.book-toggle.btn.btn-default{href: '#', "ng-click" => "book.showCopies = !book.showCopies"}
          %span{"ng-show" => "!book.showCopies", "ng-pluralize" => true, count: "(book.copies | filter:copyFilter).length", when: "{'1': 'Show 1 Copy', 'other': 'Show {} Copies'}"}
          %span{"ng-show" => "book.showCopies"}
            Hide Copies
      %table.table.table-condensed{"ng-show" => "book.showCopies"}
        %thead
          %tr
            %th Title
            %th Status
            %th Location
            %th Call Number
            %th Synced At
        %tbody
          %tr.copy{"ng-repeat" => "copy in book.copies | filter:copyFilter"}
            %td{"data-title" => "Title"}
              %a{"ng-href" => "{{copy.url}}", "ng-if" => "copy.url"}
                {{ copy.title }}
              %span{"ng-if" => "!copy.url"}
                {{ copy.title }}
            %td{"data-title" => "Status"} {{ copy.status }}
            %td{"data-title" => "Location"} {{ copy.location_name }}
            %td{"data-title" => "Call Number"} {{ copy.call_number }}
            %td{"data-title" => "Last Synced At", "am-time-ago" => "copy.last_synced_at"}

:javascript
  Minuteman = {};
  Minuteman.preferredLocations = #{ActiveModel::ArraySerializer.new(@user.locations, each_serializer: LocationSerializer).to_json};
  Minuteman.allLocations = #{ActiveModel::ArraySerializer.new(Location.all, each_serializer: LocationSerializer).to_json};
  Minuteman.pusherKey = '#{Pusher.key}';
  Minuteman.bookUpdateChannel = '#{BookNotifier.book_update_channel_name(@user)}';
  Minuteman.pendingBooksChannel = '#{BookNotifier.pending_book_channel_name(@user)}';
  Minuteman.initialPendingBookCount = '#{@user.books.unsynced.count}';