From 530a94b6a3f90323c688f6ad2707de5f3096e2b7 Mon Sep 17 00:00:00 2001 From: "Schiefelbein, Andrew" Date: Tue, 9 Jun 2020 14:30:32 -0500 Subject: [PATCH] Integrating the isogen & doc pull CTL components Change-Id: Id48f6612deecf715c94ee73e7b7dbd1206602efe --- go.sum | 1 + internal/configs/configs.go | 6 + internal/integrations/ctl/airshipctl.go | 38 +++- internal/integrations/ctl/baremetal.go | 68 ++++++ internal/integrations/ctl/config.go | 205 ++++++++---------- internal/integrations/ctl/document.go | 67 ++++++ .../integrations/ctl/templates/baremetal.html | 5 + .../integrations/ctl/templates/config.html | 6 +- .../integrations/ctl/templates/document.html | 5 + internal/webservice/server.go | 5 +- web/index.html | 6 +- web/js/airshipctl/airshipctl.js | 66 ++++++ web/js/airshipctl/baremetal.js | 34 +++ .../{airshipctl.js => airshipctl/config.js} | 68 ++---- web/js/airshipctl/document.js | 34 +++ web/js/websocket.js | 12 +- 16 files changed, 445 insertions(+), 181 deletions(-) create mode 100755 internal/integrations/ctl/baremetal.go create mode 100755 internal/integrations/ctl/document.go create mode 100755 internal/integrations/ctl/templates/baremetal.html create mode 100755 internal/integrations/ctl/templates/document.html create mode 100755 web/js/airshipctl/airshipctl.js create mode 100755 web/js/airshipctl/baremetal.js rename web/js/{airshipctl.js => airshipctl/config.js} (65%) create mode 100755 web/js/airshipctl/document.js diff --git a/go.sum b/go.sum index 9aaa42a..5cc8a67 100644 --- a/go.sum +++ b/go.sum @@ -1019,6 +1019,7 @@ opendev.org/airship/airshipctl v0.0.0-20200501183051-71b06db81924/go.mod h1:ste8 opendev.org/airship/airshipctl v0.0.0-20200518155418-7276dd68d8d0 h1:gMM7Jcb0r9bEa4kYBm9mhDNIjdtLKy3WuA4z/PabpLY= opendev.org/airship/airshipctl v0.0.0-20200518155418-7276dd68d8d0/go.mod h1:0ywoz1IC0yXQ0XDfcBV/BVeEubkTPPjN7dra8sUrsHs= opendev.org/airship/airshipctl v0.0.0-20200519134509-98f14aaa9327 h1:wPnsodiekVe1lq/oxbHmk8ZCcJa1xuzPEY+yJG1lMuI= +opendev.org/airship/airshipctl v0.0.0-20200608220007-d31f4f982869 h1:JVshDs4fIvy0Fr8aN3H1xwP9NHedLBEjY+pT9AlHGbw= opendev.org/airship/go-redfish v0.0.0-20200110185254-3ab47e28bae8/go.mod h1:FEjYcb3bYBWGpQIqtvVM0NrT5eyjlCOCj5JNf4lI+6s= opendev.org/airship/go-redfish v0.0.0-20200318103738-db034d1d753a h1:4ggAMTwpfu/w3ZXOIJ9tfYF37JIYn+eNCA4O10NduZ0= opendev.org/airship/go-redfish v0.0.0-20200318103738-db034d1d753a/go.mod h1:FEjYcb3bYBWGpQIqtvVM0NrT5eyjlCOCj5JNf4lI+6s= diff --git a/internal/configs/configs.go b/internal/configs/configs.go index 02ac7d4..92c4d68 100755 --- a/internal/configs/configs.go +++ b/internal/configs/configs.go @@ -99,10 +99,16 @@ const ( SetConfig WsComponentType = "setConfig" Initialize WsComponentType = "initialize" Keepalive WsComponentType = "keepalive" + CTLConfig WsComponentType = "config" + Baremetal WsComponentType = "baremetal" + Document WsComponentType = "document" + GetDefaults WsSubComponentType = "getDefaults" SetContext WsSubComponentType = "context" SetCluster WsSubComponentType = "cluster" SetCredential WsSubComponentType = "credential" + GenerateISO WsSubComponentType = "generateISO" + DocPull WsSubComponentType = "docPull" ) // WsMessage is a request / return structure used for websockets diff --git a/internal/integrations/ctl/airshipctl.go b/internal/integrations/ctl/airshipctl.go index e5f5454..9d55dee 100755 --- a/internal/integrations/ctl/airshipctl.go +++ b/internal/integrations/ctl/airshipctl.go @@ -14,13 +14,22 @@ package ctl import ( - "log" + "bytes" + "text/template" "opendev.org/airship/airshipctl/pkg/environment" "opendev.org/airship/airshipctl/pkg/version" - "opendev.org/airship/airshipui/internal/configs" ) +// ctlPage struct is used for templated HTML +type ctlPage struct { + ClusterRows string + ContextRows string + CredentialRows string + Title string + Version string +} + // client provides a library of functions that enable external programs (e.g. Airship UI) to perform airshipctl // functionality in exactly the same manner as the CLI. type client struct { @@ -43,21 +52,26 @@ func NewClient() *client { var c *client = NewClient() // GetAirshipCTLVersion will kick out what version of airshipctl we're using -func GetAirshipCTLVersion() string { +func getAirshipCTLVersion() string { return version.Get().GitVersion } -// GetDefaults will send to the UI the basics of what airshipctl we know about -func GetDefaults(configs.WsMessage) configs.WsMessage { - config, err := getDefaultHTML() +func getHTML(templateFile string, contents ctlPage) (string, error) { + // go templates need an io writer, since we need a string this buffer can be converted + var buff bytes.Buffer + + // TODO: make the node path dynamic or setable at compile time + t, err := template.ParseFiles(templateFile) + if err != nil { - config = "Error attempting to get data for AirshipCTL configs: " + err.Error() - log.Println(err) + return "", err } - return configs.WsMessage{ - Type: configs.AirshipCTL, - Component: configs.Info, - HTML: config, + // parse and merge the template + err = template.Must(t, err).Execute(&buff, contents) + if err != nil { + return "", err } + + return buff.String(), nil } diff --git a/internal/integrations/ctl/baremetal.go b/internal/integrations/ctl/baremetal.go new file mode 100755 index 0000000..11bfdb6 --- /dev/null +++ b/internal/integrations/ctl/baremetal.go @@ -0,0 +1,68 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +package ctl + +import ( + "fmt" + + "opendev.org/airship/airshipctl/pkg/bootstrap/isogen" + "opendev.org/airship/airshipui/internal/configs" +) + +// HandleBaremetalRequest will flop between requests so we don't have to have them all mapped as function calls +func HandleBaremetalRequest(request configs.WsMessage) configs.WsMessage { + response := configs.WsMessage{ + Type: configs.AirshipCTL, + Component: configs.Baremetal, + SubComponent: request.SubComponent, + } + + var err error + var message string + switch request.SubComponent { + case configs.GetDefaults: + response.HTML, err = getBaremetalHTML() + case configs.DocPull: + message, err = c.docPull() + case configs.GenerateISO: + message, err = c.generateIso() + default: + err = fmt.Errorf("Subcomponent %s not found", request.SubComponent) + } + + if err != nil { + response.Error = err.Error() + } else { + response.Message = message + } + + return response +} + +func (c *client) generateIso() (string, error) { + var message string + err := isogen.GenerateBootstrapIso(c.settings) + if err == nil { + message = fmt.Sprintf("Success") + } + + return message, err +} + +func getBaremetalHTML() (string, error) { + return getHTML("./internal/integrations/ctl/templates/baremetal.html", ctlPage{ + Title: "Baremetal", + Version: getAirshipCTLVersion(), + }) +} diff --git a/internal/integrations/ctl/config.go b/internal/integrations/ctl/config.go index bbbf6b8..64675ed 100755 --- a/internal/integrations/ctl/config.go +++ b/internal/integrations/ctl/config.go @@ -14,134 +14,25 @@ package ctl import ( - "bytes" "fmt" - "text/template" "opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipui/internal/configs" ) -// configPage struct is used for templated HTML -type configPage struct { - ClusterRows string - ContextRows string - CredentialRows string - Title string - Version string -} - -// GetCluster gets cluster information from the airshipctl config -func (c *client) GetCluster() []*config.Cluster { - return c.settings.Config.GetClusters() -} - -// getClusterTableRows turns an array of cluster into html table rows -func getClusterTableRows() string { - info := c.GetCluster() - - var rows string - for _, config := range info { - // TODO: all rows are editable, probably shouldn't be - rows += "
" + - config.Bootstrap + "
" + - config.NameInKubeconf + "
" + - config.ManagementConfiguration + "
" + - config.KubeCluster().LocationOfOrigin + "
" + - config.KubeCluster().Server + "
" + - config.KubeCluster().CertificateAuthority + "
" + - "" - } - return rows -} - -// GetContext gets cluster information from the airshipctl config -func (c *client) GetContext() []*config.Context { - return c.settings.Config.GetContexts() -} - -// getContextTableRows turns an array of contexts into html table rows -func getContextTableRows() string { - info := c.GetContext() - - var rows string - for _, context := range info { - // TODO: all rows are editable, probably shouldn't be - rows += "
" + - context.NameInKubeconf + "
" + - context.Manifest + "
" + - context.KubeContext().LocationOfOrigin + "
" + - context.KubeContext().Cluster + "
" + - context.KubeContext().AuthInfo + "
" + - "" - } - return rows -} - -// GetCredential gets user credentials from the airshipctl config -func (c *client) GetCredential() []*config.AuthInfo { - authinfo, err := c.settings.Config.GetAuthInfos() - if err != nil { - return []*config.AuthInfo{} - } - - return authinfo -} - -// getContextTableRows turns an array of contexts into html table rows -func getCredentialTableRows() string { - info := c.GetCredential() - - var rows string - for _, credential := range info { - // TODO: all rows are editable, probably shouldn't be - rows += "" + - credential.KubeAuthInfo().LocationOfOrigin + "
" + - credential.KubeAuthInfo().Username + "
" + - "" - } - return rows -} - -func getDefaultHTML() (string, error) { - // go templates need an io writer, since we need a string this buffer can be converted - var buff bytes.Buffer - - // TODO: make the node path dynamic or setable at compile time - t, err := template.ParseFiles("./internal/integrations/ctl/templates/config.html") - - if err != nil { - return "", err - } - - // add contents to the page - p := configPage{ - ClusterRows: getClusterTableRows(), - ContextRows: getContextTableRows(), - CredentialRows: getCredentialTableRows(), - Title: "Config", - Version: GetAirshipCTLVersion(), - } - - // parse and merge the template - err = template.Must(t, err).Execute(&buff, p) - if err != nil { - return "", err - } - - return buff.String(), nil -} - -// SetConfig will flop between requests so we don't have to have them all mapped as function calls -func SetConfig(request configs.WsMessage) configs.WsMessage { +// HandleConfigRequest will flop between requests so we don't have to have them all mapped as function calls +func HandleConfigRequest(request configs.WsMessage) configs.WsMessage { response := configs.WsMessage{ - Type: configs.AirshipCTL, - Component: configs.SetConfig, + Type: configs.AirshipCTL, + Component: configs.CTLConfig, + SubComponent: request.SubComponent, } var err error var message string switch request.SubComponent { + case configs.GetDefaults: + response.HTML, err = getConfigHTML() case configs.SetContext: message, err = setContext(request) case configs.SetCluster: @@ -161,6 +52,88 @@ func SetConfig(request configs.WsMessage) configs.WsMessage { return response } +// GetCluster gets cluster information from the airshipctl config +func (c *client) getCluster() []*config.Cluster { + return c.settings.Config.GetClusters() +} + +// getClusterTableRows turns an array of cluster into html table rows +func getClusterTableRows() string { + info := c.getCluster() + + var rows string + for _, config := range info { + // TODO: all rows are editable, probably shouldn't be + rows += "
" + + config.Bootstrap + "
" + + config.NameInKubeconf + "
" + + config.ManagementConfiguration + "
" + + config.KubeCluster().LocationOfOrigin + "
" + + config.KubeCluster().Server + "
" + + config.KubeCluster().CertificateAuthority + "
" + + "" + } + return rows +} + +// GetContext gets cluster information from the airshipctl config +func (c *client) getContext() []*config.Context { + return c.settings.Config.GetContexts() +} + +// getContextTableRows turns an array of contexts into html table rows +func getContextTableRows() string { + info := c.getContext() + + var rows string + for _, context := range info { + // TODO: all rows are editable, probably shouldn't be + rows += "
" + + context.NameInKubeconf + "
" + + context.Manifest + "
" + + context.KubeContext().LocationOfOrigin + "
" + + context.KubeContext().Cluster + "
" + + context.KubeContext().AuthInfo + "
" + + "" + } + return rows +} + +// GetCredential gets user credentials from the airshipctl config +func (c *client) getCredential() []*config.AuthInfo { + authinfo, err := c.settings.Config.GetAuthInfos() + if err != nil { + return []*config.AuthInfo{} + } + + return authinfo +} + +// getContextTableRows turns an array of contexts into html table rows +func getCredentialTableRows() string { + info := c.getCredential() + + var rows string + for _, credential := range info { + // TODO: all rows are editable, probably shouldn't be + rows += "" + + credential.KubeAuthInfo().LocationOfOrigin + "
" + + credential.KubeAuthInfo().Username + "
" + + "" + } + return rows +} + +func getConfigHTML() (string, error) { + return getHTML("./internal/integrations/ctl/templates/config.html", ctlPage{ + ClusterRows: getClusterTableRows(), + ContextRows: getContextTableRows(), + CredentialRows: getCredentialTableRows(), + Title: "Config", + Version: getAirshipCTLVersion(), + }) +} + // SetCluster will take ui cluster info, translate them into CTL commands and send a response back to the UI func setCluster(request configs.WsMessage) (string, error) { modified, err := config.RunSetCluster(&request.ClusterOptions, c.settings.Config, true) diff --git a/internal/integrations/ctl/document.go b/internal/integrations/ctl/document.go new file mode 100755 index 0000000..212ce45 --- /dev/null +++ b/internal/integrations/ctl/document.go @@ -0,0 +1,67 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +package ctl + +import ( + "fmt" + + "opendev.org/airship/airshipctl/pkg/document/pull" + "opendev.org/airship/airshipui/internal/configs" +) + +// HandleBaremetalRequest will flop between requests so we don't have to have them all mapped as function calls +func HandleDocumentRequest(request configs.WsMessage) configs.WsMessage { + response := configs.WsMessage{ + Type: configs.AirshipCTL, + Component: configs.Document, + SubComponent: request.SubComponent, + } + + var err error + var message string + switch request.SubComponent { + case configs.GetDefaults: + response.HTML, err = getDocumentHTML() + case configs.DocPull: + message, err = c.docPull() + default: + err = fmt.Errorf("Subcomponent %s not found", request.SubComponent) + } + + if err != nil { + response.Error = err.Error() + } else { + response.Message = message + } + + return response +} + +func (c *client) docPull() (string, error) { + var message string + settings := pull.Settings{AirshipCTLSettings: c.settings} + err := settings.Pull() + if err == nil { + message = fmt.Sprintf("Success") + } + + return message, err +} + +func getDocumentHTML() (string, error) { + return getHTML("./internal/integrations/ctl/templates/document.html", ctlPage{ + Title: "Document", + Version: getAirshipCTLVersion(), + }) +} diff --git a/internal/integrations/ctl/templates/baremetal.html b/internal/integrations/ctl/templates/baremetal.html new file mode 100755 index 0000000..897d184 --- /dev/null +++ b/internal/integrations/ctl/templates/baremetal.html @@ -0,0 +1,5 @@ +

Airship CTL {{.Title}} Base Information

+

Version: {{.Version}}

+ +

Generate ISO

+ diff --git a/internal/integrations/ctl/templates/config.html b/internal/integrations/ctl/templates/config.html index 3348913..e6f56d4 100755 --- a/internal/integrations/ctl/templates/config.html +++ b/internal/integrations/ctl/templates/config.html @@ -21,7 +21,7 @@ {{.ClusterRows}} - +

@@ -77,7 +77,7 @@

- + @@ -130,7 +130,7 @@ {{.CredentialRows}} - +

diff --git a/internal/integrations/ctl/templates/document.html b/internal/integrations/ctl/templates/document.html new file mode 100755 index 0000000..6345250 --- /dev/null +++ b/internal/integrations/ctl/templates/document.html @@ -0,0 +1,5 @@ +

Airship CTL {{.Title}} Base Information

+

Version: {{.Version}}

+ +

Document Pull

+ diff --git a/internal/webservice/server.go b/internal/webservice/server.go index 71cc855..db4ee92 100755 --- a/internal/webservice/server.go +++ b/internal/webservice/server.go @@ -39,8 +39,9 @@ var functionMap = map[configs.WsRequestType]map[configs.WsComponentType]func(con configs.Initialize: clientInit, }, configs.AirshipCTL: { - configs.Info: ctl.GetDefaults, - configs.SetConfig: ctl.SetConfig, + configs.CTLConfig: ctl.HandleConfigRequest, + configs.Baremetal: ctl.HandleBaremetalRequest, + configs.Document: ctl.HandleDocumentRequest, }, } diff --git a/web/index.html b/web/index.html index 84e971f..8df2d13 100755 --- a/web/index.html +++ b/web/index.html @@ -12,7 +12,7 @@ - + @@ -37,7 +37,9 @@ Airship
  • { + for (let include of includes) { + var script = document.createElement("script"); + script.src = include; + document.head.appendChild(script); + } +}, false) + +// Displays the alerts from the backend +function handleCTLResponse(json) { // eslint-disable-line no-unused-vars + if (json.hasOwnProperty("error")) { + showDismissableAlert("danger", json["error"], false); + } else { + showDismissableAlert("info", json["message"], false); + } +} + +function ctlGetDefaults(element) { // eslint-disable-line no-unused-vars + let id = String(element.id); + + var json = { "type": "airshipctl", "subComponent": "getDefaults" }; + switch(id) { + case "LiBaremetal": json = Object.assign(json, { "component": "baremetal" }); break; + case "LiConfig": json = Object.assign(json, { "component": "config" }); break; + case "LiDocument": json = Object.assign(json, { "component": "document" }); break; + } + + ws.send(JSON.stringify(json)); +} + +function displayCTLInfo(json) { // eslint-disable-line no-unused-vars + if (json.hasOwnProperty("html")) { + document.getElementById("DashView").style.display = "none"; + let div = document.getElementById("ContentDiv"); + div.style.display = ""; + div.innerHTML = json["html"]; + } else { + if (json.hasOwnProperty("error")) { + showDismissableAlert("danger", json["error"], false); + } + } +} + +function buttonHelper(id,text,disabled) { // eslint-disable-line no-unused-vars + let button = document.getElementById(id); + button.innerText = text; + button.disabled = disabled; +} \ No newline at end of file diff --git a/web/js/airshipctl/baremetal.js b/web/js/airshipctl/baremetal.js new file mode 100755 index 0000000..fa139e5 --- /dev/null +++ b/web/js/airshipctl/baremetal.js @@ -0,0 +1,34 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +function baremetalAction(element) { // eslint-disable-line no-unused-vars + let elementId = element.id; + + // change text & disable the button while the process happens + buttonHelper(elementId, "In Progress", true); + + var json = { "type": "airshipctl", "component": "baremetal" }; + switch(elementId) { + case "GenIsoBtn": json = Object.assign(json, { "subComponent": "generateISO" }); break; + } + ws.send(JSON.stringify(json)); +} + +function ctlParseBaremetal(json) { // eslint-disable-line no-unused-vars + switch(json["subComponent"]) { + case "getDefaults": displayCTLInfo(json); break; + case "generateISO": buttonHelper("GenIsoBtn", "Generate ISO",false); handleCTLResponse(json); break; + default: handleCTLResponse(json) + } +} diff --git a/web/js/airshipctl.js b/web/js/airshipctl/config.js similarity index 65% rename from web/js/airshipctl.js rename to web/js/airshipctl/config.js index 4410c73..65d3273 100755 --- a/web/js/airshipctl.js +++ b/web/js/airshipctl/config.js @@ -13,39 +13,26 @@ */ function ctlGetConfig() { // eslint-disable-line no-unused-vars - console.log("Requesting airshipctl config info"); - var json = { "type": "airshipctl", "component": "info" }; + var json = { "type": "airshipctl", "component": "config", "subComponent": "getDefaults" }; ws.send(JSON.stringify(json)); } function ctlParseConfig(json) { // eslint-disable-line no-unused-vars - switch(json["component"]) { - case "info": displayInfo(json); break; - default: handleCtlResponse(json); + switch(json["subComponent"]) { + case "getDefaults": displayConfigInfo(json); break; + default: handleCTLResponse(json); } } -function displayInfo(json) { - document.getElementById("DashView").style.display = "none"; - let div = document.getElementById("ContentDiv"); - div.style.display = ""; - div.innerHTML = json["html"]; - +function displayConfigInfo(json) { + displayCTLInfo(json); enableAccordion(); } -function handleCtlResponse(json) { - if (json.hasOwnProperty("error")) { - showDismissableAlert("danger", json["error"], true); - } else { - showDismissableAlert("info", json["message"], true); - } -} - function saveConfig(element) { // eslint-disable-line no-unused-vars var json = { "type": "airshipctl", - "component": "setConfig", + "component": "config", }; tableID = getTableId(element); @@ -59,11 +46,12 @@ function saveConfig(element) { // eslint-disable-line no-unused-vars case "CredentialTable": json = Object.assign(json, saveCredential(element)); break; case "CredentialAddTable": json = Object.assign(json, addCredential(element)); break; } - - ws.send(JSON.stringify(json)); break; } } + + console.log("Save Config Request: ", json); + ws.send(JSON.stringify(json)); } function addCluster(row) { @@ -124,8 +112,8 @@ function addCredential(row) { }; } -function saveCredential(row) { - return { +function saveCredential(row) { + return { "subComponent": "credential", "authInfoOptions": { "Name": row.cells[0].textContent, @@ -148,30 +136,20 @@ function saveConfigDialog(element) { // eslint-disable-line no-unused-vars closeDialog(element); } -// This will use the cluster modal described in the pagelet that is sent via the websocket from the backend -function addClusterModal() { // eslint-disable-line no-unused-vars - let dialog = document.createElement("DIALOG"); - document.body.appendChild(dialog); - dialog.setAttribute("id", "AddCluster"); - dialog.innerHTML = document.getElementById("ClusterModalTemplate").innerHTML; - dialog.showModal(); -} +// This will use the modal described in the pagelet that is sent via the websocket from the backend +function addConfigModal(element) { // eslint-disable-line no-unused-vars + let elementId = element.id; + var id, template; + switch(elementId) { + case "ClusterBtn": id = "AddCluster"; template = "ClusterModalTemplate"; break; + case "ContextBtn": id = "AddContext"; template = "ContextModalTemplate"; break; + case "CredentialBtn": id = "AddCredential"; template = "CredentialModalTemplate"; break; + } -// This will use the context modal described in the pagelet that is sent via the websocket from the backend -function addContextModal() { // eslint-disable-line no-unused-vars let dialog = document.createElement("DIALOG"); document.body.appendChild(dialog); - dialog.setAttribute("id", "AddContext"); - dialog.innerHTML = document.getElementById("ContextModalTemplate").innerHTML; - dialog.showModal(); -} - -// This will use the context modal described in the pagelet that is sent via the websocket from the backend -function addCredentialModal() { // eslint-disable-line no-unused-vars - let dialog = document.createElement("DIALOG"); - document.body.appendChild(dialog); - dialog.setAttribute("id", "AddCredential"); - dialog.innerHTML = document.getElementById("CredentialModalTemplate").innerHTML; + dialog.setAttribute("id", id); + dialog.innerHTML = document.getElementById(template).innerHTML; dialog.showModal(); } diff --git a/web/js/airshipctl/document.js b/web/js/airshipctl/document.js new file mode 100755 index 0000000..d43cf08 --- /dev/null +++ b/web/js/airshipctl/document.js @@ -0,0 +1,34 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +function documentAction(element) { // eslint-disable-line no-unused-vars + let elementId = element.id; + + // change text & disable the button while the process happens + buttonHelper(elementId, "In Progress", true); + + var json = { "type": "airshipctl", "component": "document" }; + switch(elementId) { + case "DocPullBtn": Object.assign(json, { "subComponent": "docPull" }); break; + } + ws.send(JSON.stringify(json)); +} + +function ctlParseDocument(json) { // eslint-disable-line no-unused-vars + switch(json["subComponent"]) { + case "getDefaults": displayCTLInfo(json); break; + case "docPull": buttonHelper("DocPullBtn", "Document Pull",false); handleCTLResponse(json); break; + default: handleCTLResponse(json) + } +} diff --git a/web/js/websocket.js b/web/js/websocket.js index 25ac854..805b0f4 100755 --- a/web/js/websocket.js +++ b/web/js/websocket.js @@ -62,7 +62,7 @@ function handleMessages(message) { // create and dispatch an event based on the data received switch(json["type"]) { case "alert": showDismissableAlert(json["component"], json["message"], json["fade"]); break; - case "airshipctl": ctlParseConfig(json); break; + case "airshipctl": handleCTLMessages(json); break; case "electron": hanldleElectronMessages(json); break; default: console.log("Received message: " + json["type"]); break; } @@ -87,6 +87,16 @@ function hanldleElectronMessages(json) { } } +// helper function for the airshiptctl interactions +function handleCTLMessages(json) { + switch(json["component"]) { + case "config": ctlParseConfig(json); break; + case "baremetal": ctlParseBaremetal(json); break; + case "document": ctlParseDocument(json); break; + default: console.log("Received message: " + json); break; + } +} + function open() { console.log("Websocket established"); var json = { "type": "electron", "component": "initialize" };