Skip to content

Commit

Permalink
feat: Remove OCDS Show
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Oct 19, 2024
1 parent 93b3440 commit 59e1d60
Show file tree
Hide file tree
Showing 11 changed files with 411 additions and 1,017 deletions.
408 changes: 190 additions & 218 deletions cove_ocds/locale/en/LC_MESSAGES/django.po

Large diffs are not rendered by default.

449 changes: 221 additions & 228 deletions cove_ocds/locale/es/LC_MESSAGES/django.po

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions cove_ocds/sass/_custom-ocds.sass
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ a.view-all
text-decoration: none;


.release-badge.success
background-color: #676C3F !important
.release-badge.primary
background-color: #9baf00 !important

#container .panel
&-body dt
color: $gray;
Expand Down
312 changes: 0 additions & 312 deletions cove_ocds/templates/cove_ocds/explore_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
<a href="{% url 'index' %}" class="btn btn-large btn-success">{% trans 'Load New File' %}</a>
{% endblock %}

{% block after_head %}
{{block.super}}
<link href="https://cdn.jsdelivr.net/gh/open-contracting/[email protected]/css/custom.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/marianoguerra/[email protected]/css/json.human.css">
{% endblock %}

{% block explore_content %}
<div class="row">

Expand Down Expand Up @@ -526,310 +520,4 @@ <h2>{% trans "Save or Share these results" %}</h2>
$('#small-loading').css({"display": "inline"});
});
</script>
<script src="https://vega.github.io/vega/vega.min.js"></script>

<script src="https://cdn.jsdelivr.net/gh/open-contracting/[email protected]/js/nunjucks.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/open-contracting/[email protected]/js/merge.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/open-contracting/[email protected]/templates.js"></script>
<script src="https://cdn.jsdelivr.net/gh/marianoguerra/[email protected]/src/json.human.js"></script>
<script>
var jsonInput = $('#input-json')
var container = $('#container')
var jsonInputView = function() {
return !$("#input-json-container").hasClass("hide")
}

var gettext = function(text) {
return text
}
id_counter_value = 0
var id_counter = function() {
id_counter_value = id_counter_value + 1
return id_counter_value
}

var after_release_render = function() {
$('[data-toggle="popover"]').popover()
$('[data-toggle="tooltip"]').tooltip()

$(".extra_view").each(function (index, extra_view) {
var jq_extra_view = $(extra_view)
var extra_data = jq_extra_view.data()["extra"]
jq_extra_view.append(JsonHuman.format(extra_data))
})
}


var env = nunjucks.configure()
// this needs replacing with something readable
env.addFilter('currency', function(number) {
try {
return number.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
} catch (e) {
return ""
}
})
var render_json = function (context) {
context = context || {}
var currentValue = jsonInput.val()
if (!currentValue & jsonInputView()) {
container.html('')
return
}
if (!currentValue) {
container.html('<h1> OCDS Show. </h1> <h4>Please supply either an OCDS release or OCDS record. Use upload file or text input buttons above.</h4>')
return
}
try {
var input = JSON.parse(jsonInput.val())
} catch (e) {
container.html('<h2> Invalid JSON data </h2>')
return
}
input['gettext'] = gettext
input['id_counter'] = id_counter
if (input.hasOwnProperty("records")) {
input.ocids = input.records.map(function (value) {
return value.ocid
})
if (context.id) {
id = context.id
} else if(context.newData) {
id = input.ocids[0]
} else {
id = $('#id-select').val()
}
input['ocid'] = id
var current_record;
input.records.some(function (value) {
if (value.ocid === id) {
current_record = value
return true
}
})
var releaseNumber = context["releaseNumber"] || 0
input['releaseNumber'] = releaseNumber
input['releases'] = current_record.releases
input['releases'].sort(function (a, b) {
if (a.date) {
return a.date.localeCompare( b.date );
}
return -1
});
var prev_release = merge(input.releases.slice(0, releaseNumber))
var current_release = merge(input.releases.slice(0, releaseNumber + 1))
var changes = get_changes(flatten_all(prev_release), flatten_all(current_release))
input['release'] = augment_path(current_release)
var parties = input['release']['parties'] || []
if (!(parties instanceof Array)) {
parties = []
}
input.parties = {}
//input.socialWitness = []
parties.forEach(function (party) {
input.parties[party.id] = party
// if (party.roles && party.roles.indexOf('socialWitness') !== -1) {
// input.socialWitness.push(party)
// }
})
function get_change(obj, field) {
if (!obj) {return}
var path = obj.__path;
if (!path) {return}
var path_list = JSON.parse(path)
if (field) {
path_list.push(field)
}
var full_path = JSON.stringify(path_list)
return changes[full_path]
}
input['get_change'] = get_change
container.empty()
var content = env.render('record_select.html', input);
container.append(content)
var content = env.render('record_release.html', input);
container.append(content)
after_release_render()
} else {
input['releases'].sort(function (a, b) {
if (a.date) {
return a.date.localeCompare( b.date );
}
return -1
});
input.release_ids = input.releases.map(function (value) {
return value.id
})
if (context.id) {
id = context.id
} else if (context.newData) {
id = input.release_ids[0]
} else {
id = $('#id-select').val()
}
var current_release;
input.releases.some(function (value) {
if (value.id === id) {
current_release = value
return true
}
})
container.empty()
input['release'] = current_release
input['release_id'] = id
var parties = input['release']['parties'] || []
if (!(parties instanceof Array)) {
parties = []
}
input.parties = {}
//input.release.socialWitness = []
parties.forEach(function (party) {
input.parties[party.id] = party
// if (party.roles.indexOf('socialWitness') !== -1) {
// input.release.socialWitness.push(party)
// }
})
var content = env.render('release_select.html', input);
container.append(content)
var content = env.render('release.html', input);
container.append(content)
after_release_render()
}
// Shareholder pie chart
var shareholders = $('.shareholders-chart');
if (shareholders.length > 0) {
var data = {
'$schema': 'https://vega.github.io/schema/vega/v3.0.json',
'width': 200,
'height': 200,
'padding': 20,
'autosize': 'pad',
'data': [
{
'name': 'pieChart',
'values': null,
'transform': [
{
'type': 'pie',
'field': 'percent'
}
]
}
],
'scales': [
{
'name': 'color',
'type': 'ordinal',
'domain': {'data': 'pieChart', 'field': 'shareholder'},
'range': {'scheme': 'category20'}
}
],
'marks': [
{
'type': 'arc',
'from': {'data': 'pieChart'},
'encode': {
'enter': {
'fill': {'scale': 'color', 'field': 'shareholder'},
'x': {'signal': 'width / 2', 'value': 'field'},
'y': {'signal': 'height / 2'},
'startAngle': {'field': 'startAngle'},
'endAngle': {'field': 'endAngle'},
'innerRadius': {'value': 60},
'outerRadius': {'signal': 'width / 2'}
}
}
},
{
'type': 'text',
'from': {'data': 'pieChart'},
'encode': {
'enter': {
'x': {'field': {'group': 'width'}, 'mult': 0.5},
'y': {'field': {'group': 'height'}, 'mult': 0.5},
'radius': {'value': 80},
'theta': {'signal': '(datum.startAngle + datum.endAngle)/2'},
'fontSize': {'value': 12},
'fontWeight': {'value': 'bold'},
'fill': {'value': '#444'},
'align': {'value': 'center'},
'baseline': {'value': 'middle'},
'text': {'field': 'percentString'}
}
}
}
],
'legends': [
{
'orient': 'right',
'title': 'Shareholders',
'fill': 'color'
}
]
}
shareholders.each(function() {
var shareData = [];
var shareObj = JSON.parse(this.dataset.shareholdersChart);
shareObj.forEach(function(shareholder) {

shareData.push({
'percent': shareholder.shareholding,
'percentString': (shareholder.shareholding * 100) + '%',
"shareholder": shareholder.shareholder.name + ' (' + shareholder.shareholder.id + ')'
})
});
data.data[0].values = shareData;
var view = new vega.View(vega.parse(data))
.renderer('canvas')
.initialize(this)
.hover()
.run();
})
}
}
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}

render_json({"newData": true});
$('#input-json').on("input", function(e) {
render_json({"newData": true});
})
$('#container').on("click", ".release-button", function(e) {
e.preventDefault()
render_json({"releaseNumber": $(this).data()["releaseNumber"]})
})
$('#hide-input-button').on("click", function(e) {
e.preventDefault()
$("#input-json-container").addClass("hide")
})
$('#text-input').on("click", function(e) {
e.preventDefault()
if (jsonInputView()) {
$("#input-json-container").addClass("hide")
} else {
$("#input-json-container").removeClass("hide")
}
render_json({"newData": true});
})
$('#container').on("click", ".nav a", function(e) {
e.preventDefault()
if (!$(this).parent().hasClass("disabled")) {
$(this).tab('show');
}
})
$('#container').on("change", "#id-select", function(e) {
e.preventDefault()
render_json()
})
</script>
{% endblock extrafooterscript %}
33 changes: 0 additions & 33 deletions cove_ocds/templates/cove_ocds/explore_record.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,37 +175,4 @@ <h4 class="panel-title">
</div>
</div><!--End Row -->


{% if ocds_show_data %}
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
{% trans "Explore your data:" %}
</h4>
</div>
<div class="panel-body">
<p>
{% blocktrans %}This section provides a visual representation of the data, use it to check whether the data makes sense in the type of tool a user might use to explore it.{% endblocktrans %}
</p>
<p>
{% blocktrans %}Extensions and additional fields are hidden by default, click the 'Extra fields' buttons or open the 'Extra fields' section to view them.{% endblocktrans %}
</p>
<p>
{% blocktrans %}When viewing an OCDS record, use the numbers at the top of the visualization to browse the change history. New and changed fields are highlighted, use this feature to check whether any fields have changed unexpectedly.{% endblocktrans %}
</p>
<div id="input-json-container" class="hide">
<input id="input-json" name="input-json" value="{{ocds_show_data}}">
</div>

<div id="container">
</div>
<div id="graph"></div>
</div>
</div>
</div>
</div>
{% endif %}

{% endblock %}
Loading

0 comments on commit 59e1d60

Please sign in to comment.