-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #477 from OCHA-DAP/staging
Merge STAG to PROD
- Loading branch information
Showing
38 changed files
with
2,571 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
''' | ||
Created on Jun 2, 2014 | ||
@author: alexandru-m-g | ||
''' | ||
|
||
import ckan.plugins.toolkit as tk | ||
import beaker.cache as bcache | ||
|
||
import ckanext.hdx_theme.country_list_hardcoded as focus_countries | ||
|
||
|
||
bcache.cache_regions.update({ | ||
'hdx_memory_cache':{ | ||
'expire': 172800, # 2 days | ||
'type':'memory', | ||
'key_length': 250 | ||
} | ||
}) | ||
|
||
|
||
@bcache.cache_region('hdx_memory_cache', 'cached_group_list') | ||
def cached_group_list(): | ||
groups = tk.get_action('group_list')(data_dict={'all_fields': True}) | ||
return groups | ||
|
||
|
||
def invalidate_cached_group_list(): | ||
bcache.region_invalidate(cached_group_list, 'hdx_memory_cache', 'cached_group_list') | ||
|
||
|
||
|
||
def filter_focus_countries(group_package_stuff): | ||
focus_group_package_stuff = [] | ||
for grp_dict in group_package_stuff: | ||
if grp_dict['display_name'] in focus_countries.FOCUS_COUNTRIES: | ||
focus_group_package_stuff.append(grp_dict) | ||
|
||
return focus_group_package_stuff | ||
|
||
@bcache.cache_region('hdx_memory_cache', 'focus_countries_list') | ||
def cached_get_group_package_stuff(): | ||
group_package_stuff = tk.get_action('cached_group_list')() | ||
focus_group_package_stuff = filter_focus_countries(group_package_stuff) | ||
|
||
return sorted(focus_group_package_stuff, key=lambda k: k['title']) | ||
|
||
def invalidate_cached_get_group_package_stuff(): | ||
bcache.region_invalidate(cached_get_group_package_stuff, 'hdx_memory_cache', 'focus_countries_list') | ||
|
||
|
||
def invalidate_group_caches(): | ||
for invalidate_func in group_invalidation_functions: | ||
invalidate_func() | ||
|
||
group_invalidation_functions = [invalidate_cached_group_list, invalidate_cached_get_group_package_stuff] |
62 changes: 62 additions & 0 deletions
62
ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/bs_popover.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"use strict"; | ||
|
||
ckan.module('bs_popover', function($, _) { | ||
return { | ||
initialize : function() { | ||
var content = this.options.content; | ||
if (this.options.social_div_id) { | ||
var contentEl = $('#'+this.options.social_div_id); | ||
var newContent = contentEl.html(); | ||
contentEl.remove(); | ||
if ( newContent && newContent.length > 0 ) | ||
content = newContent; | ||
} | ||
|
||
var popoverWrapper = document.body; | ||
if (this.options.social_wrapper_div_id) { | ||
var tempPopoverWrapper = $('#'+this.options.social_wrapper_div_id); | ||
if (tempPopoverWrapper) { | ||
popoverWrapper = tempPopoverWrapper; | ||
this.popoverWrapper = tempPopoverWrapper; | ||
} | ||
} | ||
|
||
this.el.popover({ | ||
trigger : this.options.trigger, | ||
placement : this.options.placement, | ||
content : content, | ||
title : this.options.title, | ||
html: true, | ||
container: popoverWrapper | ||
}); | ||
|
||
this.el.on('click.bs_popover', $.proxy(this._onClick, this)); | ||
}, | ||
_onClick: function(e){ | ||
this.el.popover("show"); | ||
e.stopPropagation(); | ||
$('html').on('click.bs_popover', $.proxy(this._onOtherClick, this)); | ||
}, | ||
_onOtherClick: function(e) { | ||
this.el.popover("hide"); | ||
$('html').off('click.bs_popover'); | ||
|
||
}, | ||
// _isVisible: function() { | ||
// var popoverDivEls = this.popoverWrapper.find('.popover'); | ||
// if (popoverDivEls && popoverDivEls.length > 0 ) | ||
// return true; | ||
// | ||
// return false; | ||
// }, | ||
options : { | ||
placement : 'top', | ||
trigger : 'manual', | ||
content : 'Empty !', | ||
title : 'No Title !', | ||
social_div_id : null, | ||
social_wrapper_div_id: null | ||
|
||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* Follow buttons | ||
* Handles calling the API to follow the current user | ||
* | ||
* action - This being the action that the button should perform. Currently: "follow" or "unfollow" | ||
* type - The being the type of object the user is trying to support. Currently: "user" or "group" | ||
* id - id of the objec the user is trying to follow | ||
* loading - State management helper | ||
* | ||
* Examples | ||
* | ||
* <a data-module="follow" data-module-action="follow" data-module-type="user" data-module-id="{user_id}">Follow User</a> | ||
* | ||
*/ | ||
this.ckan.module('hdx_follow', function($, _) { | ||
return { | ||
/* options object can be extended using data-module-* attributes */ | ||
options : { | ||
action: null, | ||
type: null, | ||
id: null, | ||
loading: false, | ||
i18n: { | ||
follow: _('Follow'), | ||
unfollow: _('Unfollow') | ||
} | ||
}, | ||
|
||
/* Initialises the module setting up elements and event listeners. | ||
* | ||
* Returns nothing. | ||
*/ | ||
initialize: function () { | ||
$.proxyAll(this, /_on/); | ||
this.el.on('click', this._onClick); | ||
}, | ||
|
||
/* Handles the clicking of the follow button | ||
* | ||
* event - An event object. | ||
* | ||
* Returns nothing. | ||
*/ | ||
_onClick: function(event) { | ||
var options = this.options; | ||
if ( | ||
options.action | ||
&& options.type | ||
&& options.id | ||
&& !options.loading | ||
) { | ||
event.preventDefault(); | ||
var client = this.sandbox.client; | ||
var path = options.action + '_' + options.type; | ||
options.loading = true; | ||
this.el.addClass('disabled'); | ||
client.call('POST', path, { id : options.id }, this._onClickLoaded); | ||
} | ||
}, | ||
|
||
/* Fired after the call to the API to either follow or unfollow | ||
* | ||
* json - The return json from the follow / unfollow API call | ||
* | ||
* Returns nothing. | ||
*/ | ||
_onClickLoaded: function(json) { | ||
var options = this.options; | ||
var sandbox = this.sandbox; | ||
options.loading = false; | ||
this.el.removeClass('disabled'); | ||
var followers = $(this.el).parent().parent().find(".followersNumber").find("span"); | ||
var next_val = parseInt(followers.html()); | ||
if (options.action == 'follow') { | ||
options.action = 'unfollow'; | ||
this.el.html(this.i18n('unfollow')); | ||
next_val = next_val + 1; | ||
} else { | ||
options.action = 'follow'; | ||
this.el.html(this.i18n('follow')); | ||
next_val = next_val - 1; | ||
} | ||
followers.html(next_val); | ||
sandbox.publish('follow-' + options.action + '-' + options.id); | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.