Commit 724f3ab3 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Improve intent gadget to be handle Error better

See merge request nexedi/slapos.core!523
parents 0d691d7f 25ec1d12
Pipeline #27929 failed with stage
in 0 seconds
......@@ -259,7 +259,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_hal_json_style/SaleInvoiceTransaction_getRelatedPaymentTransactionIntegrationId',
'slapos_hal_json_style/SoftwareInstallation_getSoftwareReleaseInformation',
'slapos_hal_json_style/SoftwareInstance_getReportedState',
'slapos_hal_json_style/SoftwareProduct_getSoftwareReleaseAsHateoas',
'slapos_hal_json_style/SoftwareRelease_requestInstanceTree',
'slapos_hal_json_style/SoftwareRelease_requestSoftwareInstallation',
'slapos_hal_json_style/SupportRequest_close',
......
......@@ -8,7 +8,7 @@
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Site List</title>
<title>Intent page</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
......@@ -19,7 +19,9 @@
</head>
<body>
<p> Wait, you are going to be redirected automatically. </p>
<div class="message">
<p> Wait, you are going to be redirected automatically. </p>
</div>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>982.16656.9604.44475</string> </value>
<value> <string>1008.12324.34619.3993</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1583501586.17</float>
<float>1683223974.87</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -27,32 +27,6 @@
return this.triggerSubmit();
})
.onEvent('submit', function () {
var gadget = this;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (doc) {
return gadget.getSetting("hateoas_url")
.push(function (url) {
return gadget.jio_putAttachment(doc.relative_url,
url + doc.relative_url + "/SoftwareRelease_requestInstanceTree", doc);
});
})
.push(function () {
return gadget.notifySubmitted({message: gadget.message_tranlation, status: 'success'})
.push(function () {
// Workaround, find a way to open document without break gadget.
return gadget.redirect({"command": "change",
"options": {"jio_key": "/", "page": "slap_service_list"}});
});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
......@@ -90,7 +64,7 @@
});
})
.onStateChange(function (options) {
this.deferRender(options);
return this.deferRender(options);
})
.declareJob("deferRender", function (options) {
var gadget = this;
......@@ -99,9 +73,13 @@
}
return new RSVP.Queue()
.push(function () {
return gadget.updateHeader({
page_title: gadget.page_title_translation
});
return gadget.getUrlFor({command: 'history_previous'})
.push(function (selection_url) {
return gadget.updateHeader({
page_title: gadget.page_title_translation,
selection_url: selection_url
});
});
})
.push(function () {
return gadget.getSetting("hateoas_url")
......@@ -114,6 +92,12 @@
});
})
.push(function (jio_key) {
var div;
if ((jio_key === undefined) || (jio_key === "")) {
div = gadget.element.querySelector("div.message");
div.textContent = gadget.error_translation + ": could not find software release";
return div;
}
if (options.auto === undefined) {
return gadget.redirect({"command": "change",
"options": {"jio_key": jio_key, "page": "slap_add_instance_tree",
......@@ -121,58 +105,61 @@
}
// The auto is set, so we move foward to auto request the SR
options.jio_key = jio_key;
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.jio_get(jio_key),
gadget.getSetting("hateoas_url")
]);
})
.push(function (result) {
var software_release = result[1],
url = result[2],
doc = {
url_string: software_release.url_string,
title: options.software_title ? options.software_title: gadget.software_title_translation + "{uid}",
relative_url: options.jio_key
};
if (options.software_type) {
doc.software_type = options.software_type;
}
if (options.text_content) {
doc.text_content = options.text_content;
}
if (options.shared) {
doc.shared = options.shared;
}
if (options.sla_xml) {
doc.sla_xml = options.sla_xml;
}
return gadget.notifySubmitting()
return new RSVP.Queue()
.push(function () {
var query = [];
query.push("title=" + encodeURIComponent(doc.title));
if (doc.software_type) {
query.push("software_type=" + encodeURIComponent(doc.software_type));
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.jio_get(jio_key),
gadget.getSetting("hateoas_url")
]);
})
.push(function (result) {
var software_release = result[1],
url = result[2],
doc = {
url_string: software_release.url_string,
title: options.software_title ? options.software_title: gadget.software_title_translation + "{uid}",
relative_url: options.jio_key
};
if (options.software_type) {
doc.software_type = options.software_type;
}
if (doc.shared) {
query.push("shared:int=" + encodeURIComponent(doc.shared));
if (options.text_content) {
doc.text_content = options.text_content;
}
if (doc.text_content) {
query.push("text_content=" + encodeURIComponent(doc.text_content));
if (options.shared) {
doc.shared = options.shared;
}
if (doc.sla_xml) {
query.push("sla_xml=" + encodeURIComponent(doc.sla_xml));
if (options.sla_xml) {
doc.sla_xml = options.sla_xml;
}
return gadget.jio_getAttachment(doc.relative_url,
url + doc.relative_url + "/SoftwareRelease_requestInstanceTree?" + query.join("&"));
})
.push(function (key) {
return gadget.notifySubmitted({message: gadget.message_tranlation, status: 'success'})
return gadget.notifySubmitting()
.push(function () {
// Workaround, find a way to open document without break gadget.
return gadget.redirect({"command": "change",
"options": {"jio_key": key, "page": "slap_controller"}});
var query = [];
query.push("title=" + encodeURIComponent(doc.title));
if (doc.software_type) {
query.push("software_type=" + encodeURIComponent(doc.software_type));
}
if (doc.shared) {
query.push("shared:int=" + encodeURIComponent(doc.shared));
}
if (doc.text_content) {
query.push("text_content=" + encodeURIComponent(doc.text_content));
}
if (doc.sla_xml) {
query.push("sla_xml=" + encodeURIComponent(doc.sla_xml));
}
return gadget.jio_getAttachment(doc.relative_url,
url + doc.relative_url + "/SoftwareRelease_requestInstanceTree?" + query.join("&"));
})
.push(function (key) {
return gadget.notifySubmitted({message: gadget.message_tranlation, status: 'success'})
.push(function () {
// Workaround, find a way to open document without break gadget.
return gadget.redirect({"command": "change",
"options": {"jio_key": key, "page": "slap_controller"}});
});
});
});
});
......
......@@ -283,7 +283,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>986.45437.22132.61764</string> </value>
<value> <string>1008.12332.26729.18090</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -303,7 +303,7 @@
</tuple>
<state>
<tuple>
<float>1602259520.17</float>
<float>1683224657.13</float>
<string>UTC</string>
</tuple>
</state>
......
import json
software_release_relative_url = ""
kw = {
"software_release_url" : software_release,
"strict": strict
}
if software_release.startswith("product."):
software_release_list = context.SoftwareProduct_getSortedSoftwareReleaseList(software_product_reference=software_release[8:])
else:
software_release_list = context.SoftwareProduct_getSortedSoftwareReleaseList(software_release_url=software_release, strict=strict)
kw = {"software_product_reference": software_release[8:]}
software_release_list = context.SoftwareProduct_getSortedSoftwareReleaseList(**kw)
if len(software_release_list):
software_release_document = software_release_list[0]
software_release_relative_url = software_release_list[0].getRelativeUrl()
return json.dumps(software_release_document.getRelativeUrl())
return json.dumps(software_release_relative_url)
......@@ -1739,4 +1739,64 @@ class TestInstanceTree_getFastInputDict(TestSlapOSHalJsonStyleMixin):
self.assertEqual({
'enabled': True,
'sla_xml': '<parameter id="instance_guid">%s</parameter>' % software_instance.getReference()
}, self.instance_tree.InstanceTree_getFastInputDict())
\ No newline at end of file
}, self.instance_tree.InstanceTree_getFastInputDict())
class TestSoftwareProduct_getSoftwareReleaseAsHateoas(TestSlapOSHalJsonStyleMixin):
@simulate('SoftwareProduct_getSortedSoftwareReleaseList',
'software_product_reference=None, software_release_url=None, strict=None', """
assert software_product_reference == 'fake'
assert software_release_url is None
assert strict is None
return context.REQUEST['test_software_release_list']""")
def test_product_reference(self):
sr = self._makeSoftwareRelease()
self.changeSkin('RJS')
self.portal.REQUEST['test_software_release_list'] = [sr]
self.assertEqual(
sr.getRelativeUrl(),
json.loads(
self.portal.SoftwareProduct_getSoftwareReleaseAsHateoas("product.fake"))
)
@simulate('SoftwareProduct_getSortedSoftwareReleaseList',
'software_product_reference=None, software_release_url=None, strict=None', """
assert software_product_reference is None
assert software_release_url == 'fake'
assert strict is False
return context.REQUEST['test_software_release_list']""")
def test_software_release(self):
sr = self._makeSoftwareRelease()
self.changeSkin('RJS')
self.portal.REQUEST['test_software_release_list'] = [sr]
self.assertEqual(
sr.getRelativeUrl(),
json.loads(
self.portal.SoftwareProduct_getSoftwareReleaseAsHateoas("fake"))
)
@simulate('SoftwareProduct_getSortedSoftwareReleaseList',
'software_product_reference=None, software_release_url=None, strict=None', """
assert software_product_reference is None
assert software_release_url == 'fake'
assert strict is True
return []""")
def test_software_release_not_found(self):
self.changeSkin('RJS')
self.assertEqual(
'',
json.loads(
self.portal.SoftwareProduct_getSoftwareReleaseAsHateoas("fake", True))
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment