diff --git a/calliope_app/api/fixtures/admin_parameter.json b/calliope_app/api/fixtures/admin_parameter.json index 2c85513a..a58d02a8 100644 --- a/calliope_app/api/fixtures/admin_parameter.json +++ b/calliope_app/api/fixtures/admin_parameter.json @@ -3425,7 +3425,7 @@ "is_essential": "True", "is_carrier": "True", "choices": "[]", - "tags": "[\"carrier\", \"essential\", \"carrier_in\", \"required_carrier\", \"units_in\"]", + "tags": "[\"carrier\", \"essential\", \"carrier_in\", \"required_carrier\", \"units_in\", \"carrier_multiselect\"]", "index": "[]", "dim": "[]" }, @@ -3451,7 +3451,7 @@ "is_essential": "True", "is_carrier": "True", "choices": "[]", - "tags": "[\"carrier\", \"essential\", \"carrier_out\", \"required_carrier\", \"units_out\"]", + "tags": "[\"carrier\", \"essential\", \"carrier_out\", \"required_carrier\", \"units_out\", \"carrier_multiselect\"]", "index": "[]", "dim": "[]" }, diff --git a/calliope_app/api/models/configuration.py b/calliope_app/api/models/configuration.py index bfee4a0e..92141f42 100644 --- a/calliope_app/api/models/configuration.py +++ b/calliope_app/api/models/configuration.py @@ -1426,7 +1426,7 @@ def get_tech_params_dict(level, id, excl_ids=None, systemwide=True): "parameter__name", parameter__pretty_name, parameter__description, "parameter__is_essential", "parameter__is_carrier", "parameter__units", "parameter__choices", - "parameter__timeseries_enabled"] + "parameter__timeseries_enabled", "parameter__tags"] # Get Params based on Level if level == '0_abstract': @@ -1482,7 +1482,9 @@ def get_tech_params_dict(level, id, excl_ids=None, systemwide=True): 'timeseries_enabled': param["parameter__timeseries_enabled"], 'timeseries': param["timeseries"] if 'timeseries' in param.keys() else False, 'timeseries_meta_id': param["timeseries_meta_id"] if 'timeseries_meta_id' in param.keys() else 0, - 'value': param["value"] if "value" in param.keys() else param["default_value"]} + 'value': param["value"] if "value" in param.keys() else param["default_value"], + 'tags': param["parameter__tags"] + } data.append(param_dict) return data, list(set(new_excl_ids)) diff --git a/calliope_app/client/component_views/configuration.py b/calliope_app/client/component_views/configuration.py index ff38bbfe..423be098 100644 --- a/calliope_app/client/component_views/configuration.py +++ b/calliope_app/client/component_views/configuration.py @@ -153,15 +153,14 @@ def all_tech_params(request): for carrier in model.carriers_old: if carrier not in carriers.keys(): carriers[carrier] = {'rate':'kW','quantity':'kWh'} - carriers = [{'name':c,'rate':v['rate'],'quantity':v['quantity']} for c,v in carriers.items()] - for param in parameters: param['raw_units'] = param['units'] timeseries = Timeseries_Meta.objects.filter(model=model, failure=False, is_uploading=False) - + carrier_multiselect = ParamsManager.get_tagged_params('carrier_multiselect') + print(carrier_multiselect, carriers) # Technology Definition context = {"technology": technology, "essentials": essentials, @@ -170,13 +169,14 @@ def all_tech_params(request): "cplus_carrier_ids": ParamsManager.get_tagged_params('cplus_carrier'), "units_in_ids": ParamsManager.get_tagged_params('units_in'), "units_out_ids": ParamsManager.get_tagged_params('units_out'), - "can_edit": can_edit} + "carrier_multiselect": carrier_multiselect, + "can_edit": can_edit, + } html_essentials = list(render(request, 'technology_essentials.html', context))[0] emissions = ParamsManager.emission_categories() - # Parameters Table context = { "technology": technology, @@ -186,7 +186,9 @@ def all_tech_params(request): "level": "1_tech", "timeseries": timeseries, "can_edit": can_edit, - "emissions": emissions + "emissions": emissions, + "carrier_multiselect_tuples": carrier_multiselect, + } html_parameters = list(render(request, 'technology_parameters.html', context))[0] diff --git a/calliope_app/client/static/js/technologies.js b/calliope_app/client/static/js/technologies.js index 15ee4d80..147ef732 100644 --- a/calliope_app/client/static/js/technologies.js +++ b/calliope_app/client/static/js/technologies.js @@ -1,95 +1,97 @@ -$( document ).ready(function() { - - initiate_units(); - - $('#master-new').removeClass('hide'); - - if ($("#technology option").length == 0) { - $('#tech_essentials').html('


Create a technology by clicking the "+ New" button above!

'); - } else { - $('#technology').on('change', function() { - get_tech_parameters(); - }); - get_tech_parameters(); - } - - // Save modified parameters - $('#master-save').on('click', function() { - - if (validate_params()) { - - var form_data_1 = $("#form_data_1 :input").serializeJSON(); - var form_data_2 = filter_param_inputs($("#form_data_2 :input")).serializeJSON(); - var form_data = Object.assign({}, form_data_1, form_data_2); - - $.ajax({ - url: '/' + LANGUAGE_CODE + '/api/update_tech_params/', - type: 'POST', - data: { - 'model_uuid': $('#header').data('model_uuid'), - 'technology_id': $("#technology option:selected").data('id'), - 'form_data': JSON.stringify(form_data), - 'csrfmiddlewaretoken': getCookie('csrftoken'), - }, - dataType: 'json', - success: function (data) { - window.onbeforeunload = null; - location.reload(); - } - }); - - }; - }); - - $('#master-new').on('click', function() { - var model_uuid = $('#header').data('model_uuid'); - window.location = '/' + model_uuid + '/add_technologies/'; - }); - - $('#master-cancel').on('click', function() { - window.onbeforeunload = null; - var model_uuid = $('#header').data('model_uuid'); - window.location = '/' + model_uuid + '/technologies/'; - }); - - $('#master-bulk-up').removeClass('hide'); - $('#master-bulk-up').on('click', function(){ - var model_uuid = $('#header').data('model_uuid'); - //e.stopPropagation(); - var uploadForm = document.createElement('form'); - uploadForm.id = 'uploadForm'; - uploadForm.method='post'; - uploadForm.action='/' + LANGUAGE_CODE + '/api/upload_techs/'; - uploadForm.enctype = 'multipart/form-data'; - var modelInput = document.createElement('input'); - modelInput.name = 'model_uuid'; - modelInput.value = model_uuid; - uploadForm.appendChild(modelInput); - var csrfInput = document.createElement('input'); - csrfInput.name = 'csrfmiddlewaretoken'; - csrfInput.value = getCookie('csrftoken'); - uploadForm.appendChild(csrfInput); - var fileInput = document.createElement('input'); - var submit_outputs= document.createElement('input'); - submit_outputs.type = 'submit'; - submit_outputs.id = 'submit_outputs'; - uploadForm.appendChild(submit_outputs); - - fileInput.type = 'file'; - fileInput.name = 'myfile'; - fileInput.multiple = false; - fileInput.onchange = function(){ - - $('#submit_outputs').click(); - uploadForm.remove(); - }; - - uploadForm.appendChild(fileInput); - $(document.body.append(uploadForm)); - fileInput.click(); - }); - - $('#master-bulk-down').removeClass('hide'); - $('#master-bulk-down').attr("href", function() { return $(this).attr("href")+"&file_list=technologies"}); - +$(document).ready(function () { + initiate_units(); + + $("#master-new").removeClass("hide"); + + if ($("#technology option").length == 0) { + $("#tech_essentials").html( + '


Create a technology by clicking the "+ New" button above!

' + ); + } else { + $("#technology").on("change", function () { + get_tech_parameters(); + }); + get_tech_parameters(); + } + + // Save modified parameters + $("#master-save").on("click", function () { + if (validate_params()) { + var form_data_1 = $("#form_data_1 :input").serializeJSON( + (useIntKeysAsArrayIndex = true) + ); + var form_data_2 = filter_param_inputs( + $("#form_data_2 :input") + ).serializeJSON(); + var form_data = Object.assign({}, form_data_1, form_data_2); + + $.ajax({ + url: "/" + LANGUAGE_CODE + "/api/update_tech_params/", + type: "POST", + data: { + model_uuid: $("#header").data("model_uuid"), + technology_id: $("#technology option:selected").data("id"), + form_data: JSON.stringify(form_data), + csrfmiddlewaretoken: getCookie("csrftoken"), + }, + dataType: "json", + success: function (data) { + window.onbeforeunload = null; + location.reload(); + }, + }); + } + }); + + $("#master-new").on("click", function () { + var model_uuid = $("#header").data("model_uuid"); + window.location = "/" + model_uuid + "/add_technologies/"; + }); + + $("#master-cancel").on("click", function () { + window.onbeforeunload = null; + var model_uuid = $("#header").data("model_uuid"); + window.location = "/" + model_uuid + "/technologies/"; + }); + + $("#master-bulk-up").removeClass("hide"); + $("#master-bulk-up").on("click", function () { + var model_uuid = $("#header").data("model_uuid"); + //e.stopPropagation(); + var uploadForm = document.createElement("form"); + uploadForm.id = "uploadForm"; + uploadForm.method = "post"; + uploadForm.action = "/" + LANGUAGE_CODE + "/api/upload_techs/"; + uploadForm.enctype = "multipart/form-data"; + var modelInput = document.createElement("input"); + modelInput.name = "model_uuid"; + modelInput.value = model_uuid; + uploadForm.appendChild(modelInput); + var csrfInput = document.createElement("input"); + csrfInput.name = "csrfmiddlewaretoken"; + csrfInput.value = getCookie("csrftoken"); + uploadForm.appendChild(csrfInput); + var fileInput = document.createElement("input"); + var submit_outputs = document.createElement("input"); + submit_outputs.type = "submit"; + submit_outputs.id = "submit_outputs"; + uploadForm.appendChild(submit_outputs); + + fileInput.type = "file"; + fileInput.name = "myfile"; + fileInput.multiple = false; + fileInput.onchange = function () { + $("#submit_outputs").click(); + uploadForm.remove(); + }; + + uploadForm.appendChild(fileInput); + $(document.body.append(uploadForm)); + fileInput.click(); + }); + + $("#master-bulk-down").removeClass("hide"); + $("#master-bulk-down").attr("href", function () { + return $(this).attr("href") + "&file_list=technologies"; + }); }); diff --git a/calliope_app/client/templates/carrier_form_multiselect.html b/calliope_app/client/templates/carrier_form_multiselect.html new file mode 100644 index 00000000..7344a0d1 --- /dev/null +++ b/calliope_app/client/templates/carrier_form_multiselect.html @@ -0,0 +1,216 @@ + + + +
+ {% if not carrier.value.0 %} {% endif %} + {{ carrier.name }}: +
+ +
+ +
+ + + + diff --git a/calliope_app/client/templates/carrier_form_simple.html b/calliope_app/client/templates/carrier_form_simple.html index 03dbc7ca..89f43a84 100644 --- a/calliope_app/client/templates/carrier_form_simple.html +++ b/calliope_app/client/templates/carrier_form_simple.html @@ -7,7 +7,6 @@