on xenial help sign in
Do not create fallback code for the card tool fake card

Causes issues with layouting

commita552d24ba562b65db05f74eb5e8ff000cd929bfe authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 16 Feb 2016, 13:29 (11 years ago) parent96a9bce
4 files changed+13−12
plugins/Dash/CardCreator.js+5−5 plugins/Dash/CardCreatorCache.qml+4−3 qml/Dash/CardTool.qml+2−2 tests/plugins/Dash/cardcreatortest.qml+2−2
plugins/Dash/CardCreator.js+5−5
@@ -398,7 +398,7 @@ function sanitizeColor(colorString) {
398398 return colorString;
399399}
400400
401−function cardString(template, components) {
401+function cardString(template, components, isCardTool) {
402402 var code;
403403
404404 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
@@ -497,7 +497,7 @@ function cardString(template, components) {
497497 if (isNaN(aspectRatio)) {
498498 aspectRatio = 1;
499499 }
500− var fallback = components["art"] && components["art"]["fallback"] || "";
500+ var fallback = !isCardTool && components["art"] && components["art"]["fallback"] || "";
501501 fallback = encodeURI(fallback);
502502 var fallbackStatusCode = "";
503503 var fallbackURICode = '""';
@@ -599,7 +599,7 @@ function cardString(template, components) {
599599 }
600600
601601 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
602− var fallback = components["mascot"] && components["mascot"]["fallback"] || "";
602+ var fallback = !isCardTool && components["mascot"] && components["mascot"]["fallback"] || "";
603603 fallback = encodeURI(fallback);
604604 var fallbackStatusCode = "";
605605 var fallbackURICode = '""';
@@ -854,13 +854,13 @@ function cardString(template, components) {
854854 return code;
855855}
856856
857−function createCardComponent(parent, template, components, identifier) {
857+function createCardComponent(parent, template, components, isCardTool, identifier) {
858858 var imports = 'import QtQuick 2.4; \n\
859859 import Ubuntu.Components 1.3; \n\
860860 import Ubuntu.Settings.Components 0.1; \n\
861861 import Dash 0.1;\n\
862862 import Utils 0.1;\n';
863− var card = cardString(template, components);
863+ var card = cardString(template, components, isCardTool);
864864 var code = imports + 'Component {\n' + card + '}\n';
865865
866866 try {
plugins/Dash/CardCreatorCache.qml+4−3
@@ -23,16 +23,17 @@ QtObject {
2323
2424 property var cache: new Object();
2525
26− function getCardComponent(template, components) {
26+ function getCardComponent(template, components, isCardTool) {
2727 if (template === undefined || components === undefined)
2828 return undefined;
2929
3030 var tString = JSON.stringify(template);
3131 var cString = JSON.stringify(components);
32− var allString = tString + cString;
32+ var allString = tString + cString + isCardTool;
33+ console.log(allString);
3334 var component = cache[allString];
3435 if (component === undefined) {
35− component = CardCreator.createCardComponent(root, template, components, allString);
36+ component = CardCreator.createCardComponent(root, template, components, isCardTool, allString);
3637 cache[allString] = component;
3738 }
3839 return component;
qml/Dash/CardTool.qml+2−2
@@ -66,7 +66,7 @@ Item {
6666 return layout;
6767 }
6868
69− property var cardComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components);
69+ property var cardComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, false);
7070
7171 // FIXME: Saviq
7272 // Only way for the card below to actually be laid out completely.
@@ -216,7 +216,7 @@ Item {
216216 "summary": "—\n—\n—\n—\n—",
217217 "attributes": attributesModel.model
218218 }
219− sourceComponent: cardTool.cardComponent
219+ sourceComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, true);
220220 onLoaded: {
221221 item.objectName = "cardToolCard";
222222 item.asynchronous = false;
tests/plugins/Dash/cardcreatortest.qml+2−2
@@ -20,10 +20,10 @@ import "../../../plugins/Dash/CardCreator.js" as CardCreator
2020Item {
2121 id: root
2222 function cardString(template, components) {
23− return CardCreator.cardString(JSON.parse(template), JSON.parse(components));
23+ return CardCreator.cardString(JSON.parse(template), JSON.parse(components), false);
2424 }
2525
2626 function createCardComponent(template, components) {
27− return CardCreator.createCardComponent(root, JSON.parse(template), JSON.parse(components)) !== null;
27+ return CardCreator.createCardComponent(root, JSON.parse(template), JSON.parse(components), false) !== null;
2828 }
2929}