From 671341fc387eabb855bc43457d3b943ecc293120 Mon Sep 17 00:00:00 2001 From: rgrp Date: Tue, 16 Aug 2011 09:57:31 +0100 Subject: [PATCH] [refactor,search][m]: refactor DatasetSearchView to use dataset-listing views developed by aron for search widget rather than DatasetSummaryView. * Overhaul and improve search view test * Fix up layout of html in test/index.html (xs) * Minor tweaks to DatasetListingItem to include some template from DatasetSummaryView not in there yet (e.g. actions) --- app/css/ckanjs.css | 12 ++++++++ app/index.html | 1 + lib/templates.js | 40 ------------------------- lib/view.js | 59 ++++++++----------------------------- lib/view/dataset-listing.js | 22 +++++++++++--- test/index.html | 13 ++++---- test/view-test.js | 40 ++++++++++++------------- 7 files changed, 69 insertions(+), 118 deletions(-) diff --git a/app/css/ckanjs.css b/app/css/ckanjs.css index e1927c0..6925db7 100644 --- a/app/css/ckanjs.css +++ b/app/css/ckanjs.css @@ -124,6 +124,18 @@ ul.actions li { line-height: 12px; } +/**************************************** + * Search View + ***************************************/ + +.results h3 { + margin-top: 1em; +} + +.results > p { + margin-bottom: 0; +} + /**************************************** * Dataset Edit/Create ***************************************/ diff --git a/app/index.html b/app/index.html index b2d8682..7f22c92 100644 --- a/app/index.html +++ b/app/index.html @@ -51,6 +51,7 @@ + diff --git a/lib/templates.js b/lib/templates.js index 09e94fd..5927875 100644 --- a/lib/templates.js +++ b/lib/templates.js @@ -1,46 +1,6 @@ var CKAN = CKAN || {}; CKAN.Templates = { - datasetSummary: ' \ -
  • \ -
    \ - \ - ${dataset.displaytitle} \ - \ -
    \ - {{if dataset.resources.length}} \ -
      \ - {{each dataset.resources}} \ -
    • ${$value.format}
    • \ - {{/each}} \ -
    \ - {{/if}} \ -
    \ -
    \ -
    \ - {{html dataset.snippet}} \ -
    \ -
    \ - {{if dataset.tags.length}} \ -
      \ - {{each dataset.tags}} \ -
    • ${$value}
    • \ - {{/each}} \ -
    \ - {{/if}} \ -
    \ - \ -
  • \ - ', - minorNavigationDataset: ' \ \ {{/if}} \ - ' + \ + \ + ' }, constructor: function DatasetListingItem() { @@ -103,7 +113,11 @@ this.CKAN.View || (this.CKAN.View = {}); var data = _.extend(this.model.toTemplateJSON(), { dataset: this.model.toTemplateJSON(), domain: this.options.domain, - formats: this._availableFormats() + formats: this._availableFormats(), + urls: { + datasetView: CKAN.UI.workspace.url('dataset', 'view', this.model.id), + datasetEdit: CKAN.UI.workspace.url('dataset', 'edit', this.model.id) + } }); this.el.html($.tmpl(this.options.template, data)); return this; diff --git a/test/index.html b/test/index.html index 015af65..5d9cf8c 100644 --- a/test/index.html +++ b/test/index.html @@ -40,15 +40,14 @@

    Results

    + -
    -
    - - +
    +
    + diff --git a/test/view-test.js b/test/view-test.js index 9517127..b31a43d 100644 --- a/test/view-test.js +++ b/test/view-test.js @@ -2,17 +2,6 @@ module("View"); CKAN.UI.initialize() -test("DatasetSummaryView", function () { - var pkg = new CKAN.Model.Dataset(datasets[1]); - var view = new CKAN.View.DatasetSummaryView({ - model: pkg - }); - view.render(); - var tmpl = $(view.el); - var title = tmpl.find('.title a').text(); - equals(title, 'A Novel By Tolstoy'); -}); - test("DatasetFullView", function () { var pkg = new CKAN.Model.Dataset(datasets[1]); var $view = $('
    ').appendTo($('.fixture')); @@ -61,17 +50,28 @@ test("DatasetEditView", function () { }); test("DatasetSearchView", function () { - var coll = new CKAN.Model.SearchCollection([]); - - var searchView = new CKAN.View.DatasetSearchView({ + var client = new CKAN.Client(); + var view = new CKAN.View.DatasetSearchView({ el: $('#search-page'), - collection: coll + client: client }); - var pkg = new CKAN.Model.Dataset(datasets[1]); - coll.add(pkg); - searchView.addOne(pkg); - searchView.render(); - var title = $('.datasets li .title a').text(); + var _models = _.map(datasets, function(attributes) { + return client.createDataset(attributes); + }); + var _results = new CKAN.Model.SearchCollection( + _models + , {total: 2} + ); + this.stub(view.client, 'searchDatasets', function(options){ + options.success(_results); + }); + var _event = { + preventDefault: function() {} + }; + view.doSearch(_event); + var count = view.el.find('.count').text(); + equals(count, '2'); + var title = $('.datasets li .title a').last().text(); equals(title, 'A Novel By Tolstoy'); });