diff --git a/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/css/styles.css b/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/css/styles.css index ba1c82548d8..8e51761433c 100644 --- a/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/css/styles.css +++ b/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/css/styles.css @@ -1838,3 +1838,13 @@ div.consoleIcon { .jstree-deletebtn:hover { color: white; } + +.extension-not-install { + color: wheat; + font-weight: bold; +} + +.partial-extension-install-btn, +.extension-install-btn { + color: whitesmoke; +} diff --git a/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/dialog/extension-install-dialog.js b/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/dialog/extension-install-dialog.js new file mode 100644 index 00000000000..ca6074aa916 --- /dev/null +++ b/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/dialog/extension-install-dialog.js @@ -0,0 +1,236 @@ +/** + * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) Apache License, Version 2.0 + * http://www.apache.org/licenses/LICENSE-2.0 + */ +define(['require', 'lodash', 'jquery', 'constants'], + function (require, _, $, Constants) { + return function (app) { + + /** + * initialize function for ExtensionInstallDialog. + */ + this.initialize = function (options) { + this.dialog_containers = $(_.get(options.config.dialog, 'container')); + this.extensionList = app.utils.extensionData; + }, + /** + * show function for display the ExtensionInstallDialog. + */ + this.show = function () { + this._extensionListModal.modal('show'); + }, + + /** + * render function for rendering all the contents of ExtensionInstallDialog. + */ + this.render = function () { + var self = this; + if (!_.isNil(this._extensionListModal)) { + this._extensionListModal.remove(); + } + + var extensionModelOpen = $( + ""); + + var extensionInstallConfigModal = extensionModelOpen.filter("#extensionInstallConfigModalId"); + var extensionInstallError = extensionModelOpen.find("#extensionInstallErrorId"); + var extensionSearch = extensionModelOpen.find("input").filter("#extensionSearchId"); + + extensionInstallConfigModal.on('shown.bs.modal', function () { + extensionSearch.focus(); + }); + var extensionContainer = extensionModelOpen.find("div").filter("#extensionTableId"); + + //define the map to store Partially extension modal based on key + var partialExtensionDetailModal = new Map(); + renderExtensions(); + var callbackExtensionFileBrowser = function (updatedExtension, isUpdated) { + if (isUpdated) { + app.utils.extensionData.set(updatedExtension.extensionInfo.name,updatedExtension); + self.renderExtensions(); + } + }; + var extensionTable; + + this.renderExtensions = function () { + extensionContainer.empty(); + extensionTable = $('
'); + app.utils.extensionData.forEach(function (extension, key) { + var extensionTableBodyData; + if (extension.extensionStatus.trim().toUpperCase() === Constants.EXTENSION_INSTALLED) { + extensionTableBodyData = $('' + extension.extensionInfo.name + 'Installed' + Constants.UNINSTALL + ''); + extensionButtonFunctionInsert(extensionTableBodyData,extension); + } else if (extension.extensionStatus.trim().toUpperCase() === Constants.EXTENSION_PARTIALLY_INSTALLED) { + extensionTableBodyData = $('' + extension.extensionInfo.name + 'Partially-Installed' + + '   ' + Constants.UNINSTALL + ''); + createAlertModalBoxForNotAndPartialExtension(extension, key, extensionTableBodyData); + extensionButtonFunctionInsert(extensionTableBodyData,extension); + + } else if (extension.extensionStatus.trim().toUpperCase() === Constants.EXTENSION_NOT_INSTALLED) { + extensionTableBodyData = $('' + extension.extensionInfo.name + 'Not-Installed' + Constants.INSTALL + ''); + extensionButtonFunctionInsert(extensionTableBodyData,extension); + } + extensionTable.append(extensionTableBodyData); + }); + extensionContainer.append(extensionTable); + } + extensionSearch.keyup(function () { + searchExtension(extensionTable, extensionSearch.val()); + }); + $(this.dialog_containers).append(extensionModelOpen); + extensionInstallError.hide(); + this._extensionListModal = extensionModelOpen; + + /** + * insert the onclick function for extension button. + * @param extensionTableBodyData + * @param extension + * @param callbackExtensionFileBrowser + * @returns {*} + */ + function extensionButtonFunctionInsert(extensionTableBodyData,extension) { + return extensionTableBodyData.find("button").click(function () { + app.utils.extensionUpdateThroughFile(extension,callbackExtensionFileBrowser); + }); + } + + /** + * create a alert details model box for extension dependency. + * @param extension object + * @param key map key for object + * @param extensionTableBodyData is modal body + */ + function createAlertModalBoxForNotAndPartialExtension(extension, key, extensionTableBodyData) { + var partialModel = $( + ''); + + var modalBody = partialModel.find("div").filter("#modalBodyId"); + + if (extension.manuallyInstall) { + extension.manuallyInstall.forEach(function (dependency) { + modalBody.append($('

' + dependency.name + '

' + + '

Description

' + + '
' + + dependency.download.info.description + + '
' + + '

Install

' + + '
' + + dependency.download.info.install + + '
')); + }); + } + + partialExtensionDetailModal.set(key, partialModel); + + extensionTableBodyData.find("a").filter("#" + key).click(function () { + extensionPartialModelDisplay(partialExtensionDetailModal.get(key)); + }); + }; + + /** + * search function for seek the extensions. + * @param extensionTable + * @param locationSearch + */ + function searchExtension(extensionTable, locationSearch) { + var unmatchedCount = 0, filter, table, tr, td, i, txtValue; + var noResultsElement = extensionModelOpen.find("div").filter("#noResults"); + filter = locationSearch.toUpperCase(); + table = extensionTable[0]; + tr = table.getElementsByTagName("tr"); + for (i = 0; i < tr.length; i++) { + td = tr[i].getElementsByTagName("td")[0]; + if (td) { + txtValue = td.textContent || td.innerText; + if (txtValue.toUpperCase().indexOf(filter) > -1) { + tr[i].style.display = ""; + } else { + tr[i].style.display = "none"; + unmatchedCount += 1; + } + } + } + var isMatched = (unmatchedCount === tr.length); + noResultsElement.toggle(isMatched); + } + + /** + * display the inner modal box for the partially installed extension. + * @param extensionPartialModel + */ + function extensionPartialModelDisplay(extensionPartialModel) { + self._extensionPartialModel = extensionPartialModel; + self._extensionPartialModel.modal('show'); + } + } + }; + }); \ No newline at end of file diff --git a/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/dialog/module.js b/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/dialog/module.js index 728bc8d4525..f69812cd462 100644 --- a/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/dialog/module.js +++ b/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/dialog/module.js @@ -1,11 +1,11 @@ /** * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 */ -define(['./save-to-file-dialog', './replace-confirm-dialog', './open-file-dialog', './close-confirm-dialog', +define(['./save-to-file-dialog', './replace-confirm-dialog', './open-file-dialog','./extension-install-dialog', './close-confirm-dialog', './import-file-dialog', './export-file-dialog', './settings-dialog', './close-all-confirm-dialog', './delete-confirm-dialog', './open-sample-file-dialog', './export-dialog', './sample-event-dialog', './query-store-dialog', './deploy-file-dialog', './export-dialog'], - function (SaveToFileDialog, ReplaceConfirmDialog, OpenFileDialog, CloseConfirmDialog, ImportFileDialog, + function (SaveToFileDialog, ReplaceConfirmDialog, OpenFileDialog,ExtensionInstallDialog, CloseConfirmDialog, ImportFileDialog, ExportFileDialog, SettingsDialog, CloseAllConfirmDialog, DeleteConfirmDialog, OpenSampleFileDialog, DockerExportDialog, SampleEventDialog, QueryStoreDialog, DeployFileDialog, ExportDialog) { return { @@ -13,6 +13,7 @@ define(['./save-to-file-dialog', './replace-confirm-dialog', './open-file-dialog open_file_dialog: OpenFileDialog, CloseConfirmDialog: CloseConfirmDialog, ReplaceConfirmDialog: ReplaceConfirmDialog, + ExtensionInstallDialog :ExtensionInstallDialog, import_file_dialog: ImportFileDialog, export_file_dialog: ExportFileDialog, settings_dialog: SettingsDialog, diff --git a/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/menu-bar/file-menu.js b/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/menu-bar/file-menu.js index b432f8bcc16..b6374dfeaf4 100644 --- a/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/menu-bar/file-menu.js +++ b/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/menu-bar/file-menu.js @@ -60,6 +60,24 @@ define([], function () { }, disabled: false }, + { + id: "extensionInstall", + label: "Extension Installation", + command: { + id: "extension-install-dialog", + shortcuts: { + mac: { + key: "command+alt+i", + label: "\u2318\u2325I" + }, + other: { + key: "ctrl+alt+i", + label: "Ctrl+Alt+I" + } + } + }, + disabled: false + }, { id: "save", label: "Save", diff --git a/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/utils/utils.js b/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/utils/utils.js index 4141c101ab6..7d8be458cc0 100644 --- a/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/utils/utils.js +++ b/components/org.wso2.carbon.siddhi.editor.core/src/main/resources/web/editor/commons/js/utils/utils.js @@ -1,9 +1,11 @@ /** * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 */ -define(['require', 'jquery'], - function (require, $) { +define(['require', 'jquery', 'constants'], + function (require, $, Constants) { + var self = this; var Utils = function () { + this.extensionData = getExtensionDetails(); }; var rest_client_constants = { @@ -15,6 +17,167 @@ define(['require', 'jquery'], editorUrl: window.location.protocol + "//" + window.location.host + '/editor' }; + /** + * getting extension data from back end. + * @returns {Map|Map} + */ + function getExtensionDetails() { + return new Map(Object.entries({ + "kafka": { + "extensionStatus": "NOT_INSTALLED", + "extensionInfo": { + "name": "kafka", + "version": "5.0.8-SNAPSHOT" + } + }, + "redis": { + "extensionStatus": "NOT_INSTALLED", + "extensionInfo": { + "name": "redis", + "version": "3.1.2-SNAPSHOT" + }, + "manuallyInstall": [ + { + "name": "redis-clients", + "version": "2.3.0", + "download": { + "info": { + "description": "redis clients is like a one extension", + "install": "by using this way we can install redis-clients" + }, + "autoDownloadable": false, + "url": "https://repo1.maven.org/maven2/org/apache/redis/redis_2.11/2.1.1/redis_2.11-2.1.1.jar" + }, + "type": "BUNDLE", + "lookupRegex": "kafka-clients-(.+).jar" + }, + { + "name": "redis-server", + "version": "2.3.0", + "download": { + "info": { + "description": "redis clients is like a one extension", + "install": "by using this way we can install redis-clients" + }, + "autoDownloadable": false, + "url": "https://repo1.maven.org/maven2/org/apache/redis/redis_2.11/2.1.1/kafka_2.11-2.1.1.jar" + }, + "type": "BUNDLE", + "lookupRegex": "kafka-server-(.+).jar" + } + ] + }, + "grpc": { + "extensionStatus": "NOT_INSTALLED", + "extensionInfo": { + "name": "grpc", + "version": "3.1.2-SNAPSHOT" + }, + "manuallyInstall": [ + { + "name": "grpc-clients", + "version": "2.3.0", + "download": { + "info": { + "description": "grpc clients is like a one extension", + "install": "by using this way we can install grpc-clients" + }, + "autoDownloadable": false, + "url": "https://repo1.maven.org/maven2/org/apache/grpc/grpc_2.11/2.1.1/grpc_2.11-2.1.1.jar" + }, + "type": "BUNDLE", + "lookupRegex": "grpc-clients-(.+).jar" + }, + { + "name": "grpc-server", + "version": "2.3.0", + "download": { + "info": { + "description": "grpc server is like a one extension", + "install": "by using this way we can install grpc-server" + }, + "autoDownloadable": false, + "url": "https://repo1.maven.org/maven2/org/apache/grpc/grpc_2.11/2.1.1/grpc_2.11-2.1.1.jar" + }, + "type": "BUNDLE", + "lookupRegex": "grpc-server-(.+).jar" + } + ] + }, + "nats": { + "extensionStatus": "NOT_INSTALLED", + "extensionInfo": { + "name": "nats", + "version": "3.1.2-SNAPSHOT" + }, + } + })); + } + /** + * provide the update details about the extension + * @param extension + * @param callbackUpdater + * @param key + * @param callback + */ + Utils.prototype.extensionUpdateThroughFile = function (extension,callbackUpdater) { + self.extensionInstallUninstallAlertModal = $( + "