Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AppBuilder/core
Submodule core updated from d5770e to 67359e
4 changes: 3 additions & 1 deletion AppBuilder/platform/plugins/included/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import viewDocxBuilder from "./view_docxBuilder/FNAbviewdocxbuilder.js";
import viewGrid from "./view_grid/FNAbviewgrid.js";
import viewCarousel from "./view_carousel/FNAbviewcarousel.js";
import viewChart from "./view_chart/FNAbviewchart.js";
Expand Down Expand Up @@ -38,7 +39,8 @@ const AllPlugins = [
viewTab,
viewText,
viewDataview,
viewGrid
viewGrid,
viewDocxBuilder
];

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import FNAbviewdocxbuilderComponent from "./FNAbviewdocxbuilderComponent.js";

// FNAbviewdocxbuilder Web
// A web side import for an ABView.
//
export default function FNAbviewdocxbuilder({
/*AB,*/
ABViewWidgetPlugin,
ABViewComponentPlugin,
ABViewContainer,
}) {
const ABAbviewdocxbuilderComponent = FNAbviewdocxbuilderComponent({
ABViewComponentPlugin,
});

const ABViewDocxBuilderPropertyComponentDefaults = {
buttonlabel: "Download DOCX",
dataviewID: null,
width: 0,
filename: "", // uuid
filelabel: "output.docx",
language: "en", // en
toolbarBackground: "ab-background-default",
buttonPosition: "left",
};

const ABViewDefaults = {
key: "docxBuilder", // {string} unique key for this view
icon: "file-word-o", // {string} fa-[icon] reference for this view
labelKey: "DOCX Builder", // {string} the multilingual label key for the class label
};

class ABViewDocxBuilderCore extends ABViewWidgetPlugin {
constructor(values, application, parent, defaultValues) {
super(values, application, parent, defaultValues || ABViewDefaults);
}

static common() {
return ABViewDefaults;
}

static defaultValues() {
return ABViewDocxBuilderPropertyComponentDefaults;
}

///
/// Instance Methods
///

/**
* @method toObj()
*
* properly compile the current state of this ABViewLabel instance
* into the values needed for saving.
*
* @return {json}
*/
toObj() {
this.unTranslate(this, this, ["filelabel", "buttonlabel"]);

let obj = super.toObj();
obj.viewIDs = [];
return obj;
}

/**
* @method fromValues()
*
* initialze this object with the given set of values.
* @param {obj} values
*/
fromValues(values) {
super.fromValues(values);

// convert from "0" => 0
this.settings.width = parseInt(
this.settings.width ||
ABViewDocxBuilderPropertyComponentDefaults.width
);

this.translate(this, this, ["filelabel", "buttonlabel"]);
}

uploadUrl() {
// TODO: Convert this to use ABFactory.urlFileUpload() or a ABFieldFile
// to get the URL:

// support uploading template when more than one data source is selected
const object = this.datacollections[0].datasource;

// NOTE: file-upload API needs to have the id of ANY field.
const field = object ? object.fields()[0] : null;

return `/file/upload/${object?.id}/${field?.id}/1`;
}

downloadUrl() {
return `/file/${this.settings.filename}`;
}

get languageCode() {
return (
this.settings.language ||
ABViewDocxBuilderPropertyComponentDefaults.language
);
}

get datacollections() {
let dataviewID = (this.settings || {}).dataviewID;
if (!dataviewID) return [];

let dvList = dataviewID.split(",") || [];

return (
this.AB.datacollections((dv) => dvList.indexOf(dv.id) > -1) || []
);
}
}

return class ABViewDocxBuilder extends ABViewDocxBuilderCore {
/**
* @method getPluginKey
* return the plugin key for this view.
* @return {string} plugin key
*/
static getPluginKey() {
return this.common().key;
}

/**
* @method component()
* return a UI component based upon this view.
* @return {obj} UI component
*/
component(parentId) {
return new ABAbviewdocxbuilderComponent(this, parentId);
}

letUserDownload(blob, filename) {
const url = window.URL.createObjectURL(blob);

const a = document.createElement("a");
a.href = url;
a.download = filename;
document.body.appendChild(a); // we need to append the element to the dom -> otherwise it will not work in firefox
a.click();
a.remove(); //afterwards we remove the element again

window.URL.revokeObjectURL(url);
}

warningsEval() {
super.warningsEval();

let DC = this.datacollections || this.datacollection;
if (!DC) {
this.warningsMessage(
`can't resolve it's datacollection[${this.settings.dataviewID}]`
);
}

if (!this.settings.filename) {
this.warningsMessage("is missing a DOCX template file");
} else {
// TODO: should we check for the existance of the file?
// this isn't currently an async friendly fn, so how?
// let url = this.downloadUrl();
}
}
};
}
Loading
Loading