Skip to content

Commit

Permalink
Batch of Fixes (#677)
Browse files Browse the repository at this point in the history
* Resolved error loading page and tidied up display of page

* Added new values to vocabulary, as such vocabularies will need to be updated

* Updated vocabulary, vocabs will have to be updated as such

* Added missing js library so error doesn't occur calling function

* Added "Purpose" to table with other values so they are all equal headings

* Replaced 'fa-remove' with the proper font awesome alias 'fa-times'

* Updated spelling

* Added JS to force popover to activate in modal, also override of default bootstrap css so popover shows correctly in modal

* Hijacked add data button when dataset is geographic and instead of moving the form forward, save the dataset and move to the edit resources page

* Updated defaults for selecting dev_secure_call to be False rather than True since the feature should not be considered unless it's turned on in dev

* Updated hardcoded storage location from 'BCGW DataStore' to 'BC Geographic Warehouse' on both creating OFI resource and the data import script

* make api_url an ini property

* fix tab issue on input screens

* fix issue with chrome auto populate

* better checking for chrome

* changed the langauge on the error for a bad browser

* shows the same unauthorized page as the datasets show for consistency

* added modal dialog for permalink

* changed the branch link in the package view to link to the organization page instead of a search page

* add check for environment to activate snowplow
  • Loading branch information
dkelsey authored and ll911 committed Dec 18, 2018
1 parent ef8c3f6 commit bd7dc43
Show file tree
Hide file tree
Showing 27 changed files with 249 additions and 66 deletions.
37 changes: 20 additions & 17 deletions ckanext/bcgov/controllers/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _read(self, id, limit, group_type='organization'):

# Get the subgorgs of this org
org_id = c.group_dict.get('id')
hide_desc = False

q = c.q = request.params.get('q', '')

Expand All @@ -97,7 +98,6 @@ def _read(self, id, limit, group_type='organization'):
else:
sort_by = request.params.get('sort', None)


suborgs = ['"' + org + '"' for org in get_suborgs(org_id)]
if suborgs != []:
q += ' owner_org:("' + org_id + '" OR ' + ' OR '.join(suborgs) + ')'
Expand Down Expand Up @@ -303,31 +303,34 @@ def member_new(self, id):
h.flash_error(e.error_summary)
return render('organization/member_new.html', extra_vars={'errors': errors})


def about(self, id):
c.group_dict = self._get_group_dict(id)
group_type = c.group_dict['type']



context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True,
'with_private': False}

if c.userobj:
context['user_id'] = c.userobj.id
context['user_is_admin'] = c.userobj.sysadmin

#Search_result list contains all orgs matched with search criteria including orgs and suborgs.
data_dict = {'all_fields': True}
search_result = self._action('organization_list')(context, data_dict)

org_pkg_count_dict = {}
for org in search_result :
org_pkg_count_dict[org['id']] = org['packages']

c.org_pkg_count = org_pkg_count_dict

c.group_dict['package_count'] = len(c.group_dict.get('packages', []))

org_id = c.group_dict.get('id')
q = c.q = request.params.get('q', '')
suborgs = ['"' + org + '"' for org in get_suborgs(org_id)]
if suborgs != []:
q += ' owner_org:("' + org_id + '" OR ' + ' OR '.join(suborgs) + ')'
else:
q += ' owner_org:"%s"' % org_id

data_dict = {
'q': q
}

query = get_action('package_search')(context, data_dict)

c.group_dict['package_count'] = query['count']

self._setup_template_variables(context, {'id': id},
group_type=group_type)
return render(self._about_template(group_type))
8 changes: 5 additions & 3 deletions ckanext/bcgov/controllers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,12 @@ def new(self, data=None, errors=None, error_summary=None):

if save_action == 'finish' and not is_an_update and package_type == 'Geographic':
return self._new_dataset_only(package_type, data_dict, errors, error_summary)
elif save_action == 'add_data' and not is_an_update and package_type == 'Geographic':
return self._new_dataset_only(package_type, data_dict, errors, error_summary, 'resources')
else:
return super(EDCPackageController, self).new(data, errors, error_summary)

def _new_dataset_only(self, package_type, data_dict=None, errors=None, error_summary=None):
def _new_dataset_only(self, package_type, data_dict=None, errors=None, error_summary=None, redirect_link='dataset_read'):
"""
This method is for creating the actual dataset and redirecting
to the read dataset without adding any resources
Expand Down Expand Up @@ -317,7 +319,7 @@ def _new_dataset_only(self, package_type, data_dict=None, errors=None, error_sum

log.info('`finish` save param included, skipping add data view, going to dataset read view.')

toolkit.redirect_to('dataset_read', id=pkg_dict['name'])
toolkit.redirect_to(redirect_link, id=pkg_dict['name'])

except NotAuthorized:
toolkit.abort(401, _('Unauthorized to read package %s') % '')
Expand Down Expand Up @@ -723,7 +725,7 @@ def _setup_ofi(id, context=None, pkg_dict=None, open_modal=True):
if 'type' in pkg_dict and pkg_dict[u'type'] == 'Geographic':
ofi_config = edc_h.get_ofi_config()
# dev_secure_call is for working around missing siteminer session, for vagrant use only
secure_call = toolkit.asbool(ofi_config.get('dev_secure_call', True))
secure_call = toolkit.asbool(ofi_config.get('dev_secure_call', False))

ofi_resources = []
for resource in pkg_dict[u'resources']:
Expand Down
4 changes: 4 additions & 0 deletions ckanext/bcgov/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def dashboard_datasets(self):


def read(self, id=None):

if c.userobj == None:
return render('package/auth_error.html')

if c.userobj and c.userobj.sysadmin == True:
fq = ''
else:
Expand Down
31 changes: 19 additions & 12 deletions ckanext/bcgov/fanstatic/edc_dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,26 +344,33 @@ $(document).on('change', '.contact-org', function() {
var org_id = $(this).val();

var branches = [];
var replace = false;
for (var i = 0; i < contacts_org_branches.length; i++) {
if (contacts_org_branches[i].id == org_id) {
branches = contacts_org_branches[i].branches;
replace = true;
break;
}
}

var options = "<option></option>";
for (var i = 0; i < branches.length; i++) {
options += '<option value="' + branches[i].id + '">' + branches[i].name + '</option>';
}
console.log("hi");

var container = $(this).closest('.control-group.contact');
var id = container.attr('id').replace('contact_', '');
if (replace) {
var container = $(this).closest('.control-group.contact');
var id = container.attr('id').replace('contact_', '');

$("#field-contacts-" + id + "-branch").find('option').remove().end().append(options);
$("#field-contacts-" + id + "-branch").select2({
placeholder : "Select a sub-organization",
width : "220px"
});
var options = "<option></option>";
for (var i = 0; i < branches.length; i++) {
options += '<option value="' + branches[i].id + '">' + branches[i].name + '</option>';
}


$("#field-contacts-" + id + "-branch").find('option').remove().end().append(options);
$("#field-contacts-" + id + "-branch").select2({
placeholder: "Select a sub-organization",
width: "220px"
});
}

});

Expand Down Expand Up @@ -394,7 +401,7 @@ $("#form-edc_dataset").submit(function( event ) {
var previous_state;

$("#field-edc_state").change(function() {
var selected_state = $("#field-edc_state").val()
var selected_state = $("#field-edc_state").val();

if (selected_state == "PENDING PUBLISH") {
$("#state_confirm_dialog").dialog({
Expand Down
23 changes: 23 additions & 0 deletions ckanext/bcgov/fanstatic/edc_dataset_view.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#permalinkModal div.modal-content{

}

#permalinkLinkInput{
width: 90%;
float: left;
}

#permalinkDivContainer{
height: 150px;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;

-ms-flex-align: center;
-webkit-align-items: center;
-webkit-box-align: center;

align-items: center;
padding-left: 30px;
}

17 changes: 17 additions & 0 deletions ckanext/bcgov/fanstatic/edc_dataset_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);

});

$('#permalinkLink').click(function(e){
$('#permalinkModal').modal();
$('#permalinkModal').show();
e.preventDefault();
e.stopPropagation();
});

$('#permalinkModal span.close').click(function(e){
$('#permalinkModal').hide();
});

$('#copyPermalink').click(function(e) {
$('#permalinkLinkInput').select();
document.execCommand("copy");
$('#permalinkCopiedStatus').innerHTML = "Copied";
});
});

/* $("#comment-submit").click(function() {
Expand Down
2 changes: 1 addition & 1 deletion ckanext/bcgov/fanstatic/edc_gov.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ $(document).ready(function(event) {
})
//navigate menu with keyboard
$(document).keydown(function(e) {
if($("#govNavMenu").is(":visible") && !$("#govNavMenu input").is(":focus")) {
if($("#header .navbar-toggle").is(":visible") && !$("#govNavMenu input").is(":focus")) {
var currentItem= $("#govNavMenu :focus").closest("li");
switch(e.which) {
case 9: //tab - close menu
Expand Down
37 changes: 35 additions & 2 deletions ckanext/bcgov/fanstatic/edc_restrict_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,40 @@ function isUsingSupportedBrowser() {
var isFirefox = typeof InstallTrigger !== 'undefined';

// A global object inserted by Chrome
var isChrome = !!window.chrome && !!window.chrome.webstore;
var isChrome = false;


// please note,
// that IE11 now returns undefined again for window.chrome
// and new Opera 30 outputs true for window.chrome
// but needs to check if window.opr is not undefined
// and new IE Edge outputs to true now for window.chrome
// and if not iOS Chrome check
// so use the below updated condition
//as of Chrome 71 chrome no longer has the window.chrome.webstore that used to be the way this checked
//https://stackoverflow.com/a/13348618/9627526 has a continuously updated check

var isChromium = window.chrome;
var winNav = window.navigator;
var vendorName = winNav.vendor;
var isOpera = typeof window.opr !== "undefined";
var isIEedge = winNav.userAgent.indexOf("Edge") > -1;
var isIOSChrome = winNav.userAgent.match("CriOS");

if (isIOSChrome) {
// is Google Chrome on IOS
isChrome = false;
} else if(
isChromium !== null &&
typeof isChromium !== "undefined" &&
vendorName === "Google Inc." &&
isOpera === false &&
isIEedge === false
) {
isChrome = true;
} else {
isChrome = false;
}

if(isFirefox || isChrome) {
return true;
Expand All @@ -44,7 +77,7 @@ $(function() {
$primaryDiv.html('');

// Insert a warning
var warningText = "You are attempting to update or edit Data Catalogue content with a non-supported web browser. Catalogue Editors must use either <a href=\"https://www.google.com/chrome/\" target=\"_blank\">Google Chrome</a> or <a href=\"https://www.mozilla.org/en-US/firefox/new/\" target=\"_blank\">Firefox</a> when editing catalogue content. OCIO provides copies of these web browsers that can be downloaded and installed by all end users on government workstations in its <a href=\"https://selfservecentre.gov.bc.ca/\">Self-Serve Centre</a> – or they may be obtained directly from <a href=\"https://www.google.com/chrome/\" target=\"_blank\">https://www.google.com/chrome/</a> or <a href=\"https://www.mozilla.org/en-US/firefox/new/\" target=\"_blank\">https://www.mozilla.org/en-US/firefox/new/</a>.";
var warningText = "You are attempting to update or edit BC Data Catalogue content using a non-supported web browser or version. Supported browsers are Google Chrome (downloadable from <a href=\"https://www.google.com/chrome/\" target=\"_blank\">https://www.google.com/chrome/</a>) and Firefox (downloadable from <a href=\"https://www.mozilla.org/en-US/firefox/new/\" target=\"_blank\">https://www.mozilla.org/en_US/firefox/new/</a>). Not all version of these browsers are supported. If you are seeing this message and you are using Firefox or Chrome, then please report this problem to DataBC Catalogue Services.";
var $warningDiv = $('<div>' + warningText + "</div>").addClass('alert alert-danger');
$primaryDiv.prepend($warningDiv);

Expand Down
6 changes: 6 additions & 0 deletions ckanext/bcgov/fanstatic/responsive.css
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,9 @@ a:visited {
display: none!important;
}
}

/* This is a bit unrelated but it needed to be on a css file that's always loaded, overrides bootstrap defaults so popover works in modal */
.popover {
position: fixed !important;
z-index: 1060 !important;
}
2 changes: 1 addition & 1 deletion ckanext/bcgov/logic/ofi/call_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def populate_dataset_with_ofi(context, ofi_vars, ofi_resp):
resource_meta = {
u'package_id': pkg_dict['id'],
u'resource_storage_access_method': u'Indirect Access',
u'resource_storage_location': u'BCGW DataStore',
u'resource_storage_location': u'BC Geographic Warehouse',
u'projection_name': u'EPSG_3005 - NAD83 BC Albers',
u'edc_resource_type': u'Data',
u'ofi': True,
Expand Down
2 changes: 2 additions & 0 deletions ckanext/bcgov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
sort_vocab_list,
debug_full_info_as_list,
remove_user_link,
get_dashboard_config,
get_ofi_config,
get_ofi_resources,
get_non_ofi_resources,
Expand Down Expand Up @@ -128,6 +129,7 @@ def get_helpers(self):
"sort_vocab_list": sort_vocab_list,
"debug_full_info_as_list": debug_full_info_as_list,
"remove_user_link": remove_user_link,
"get_dashboard_config": get_dashboard_config,
"get_ofi_config": get_ofi_config,
"get_ofi_resources": get_ofi_resources,
"get_non_ofi_resources": get_non_ofi_resources,
Expand Down
5 changes: 4 additions & 1 deletion ckanext/bcgov/scripts/data/edc-vocabs.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"tags" : [
"Public",
"Government",
"Government and Business BCeID",
"Named users"
]
},
Expand All @@ -109,7 +110,9 @@
"tags" : [
"Public",
"Government",
"Named users"
"Government and Business BCeID",
"Named users",
"Not downloadable"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions ckanext/bcgov/scripts/data_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def import_odsi_records(con):
if resource_url.startswith('http://pub.data.gov.bc.ca/datasets') :
resource_rec['resource_storage_location'] = 'pub.data.gov.bc.ca'
elif resource_url.startswith('https://apps.gov.bc.ca/pub/dwds') :
resource_rec['resource_storage_location'] = 'BCGW Data Store'
resource_rec['resource_storage_location'] = 'BC Geographic Warehouse'

#----------------------------------------------------------< Resource Projection Name >--------------------------------------------------------------------
if edc_record.get('type') == 'Geographic':
Expand Down Expand Up @@ -1180,7 +1180,7 @@ def save_discovery_records(con, discovery_data_filename):

is_bcgw_record = False
if storage_location and 'LRDW' in storage_location :
storage_location = "BCGW Data Store"
storage_location = "BC Geographic Warehouse"
resource_rec['resource_storage_location'] = storage_location
is_bcgw_record = True
else :
Expand Down
39 changes: 39 additions & 0 deletions ckanext/bcgov/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,45 @@
</noscript>
<!-- END OF SmartSource Data Collector TAG -->

{% if h.get_environment_name() != 'DLV' and h.get_environment_name() != 'TST' %}
<!-- Snowplow starts plowing -->
<script type="text/javascript">
;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
};p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","https://sp-js.apps.gov.bc.ca/aubjyAzCUz7dJwqdbH3cMi45LjI.js","snowplow"));
var collector = 'spt.apps.gov.bc.ca';
window.snowplow('newTracker','rt',collector, {
appId: "Snowplow_standalone",
platform: 'web',
respectDoNotTrack: true,
post: true,
forceSecureTracker: true,
contexts: {
webPage: true,
performanceTiming: true
}
});
window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds
window.snowplow('enableLinkClickTracking');
window.snowplow('trackPageView');
window.snowplow('trackSiteSearch',
getUrlParamArray('q','')
);

function getUrlParamArray(param, defaultValue) {
var vars = [];
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
if ( key === param ) {
vars.push(value);
}
});
return vars;
}
</script>
<!-- Snowplow stop plowing -->
{% endif %}

{{ h.googleanalytics_header() }}

</head>
Expand Down
Loading

0 comments on commit bd7dc43

Please sign in to comment.