[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openvas-cvs
Subject:    [Openvas-commits] r29718 - in trunk/gsa: . src/html/classic/ng src/html/classic/ng/src/web/entity
From:       scm-commit () wald ! intevation ! org
Date:       2017-09-29 12:32:53
Message-ID: 20170929123254.5A6DC9A12EC4 () wald ! intevation ! org
[Download RAW message or body]

Author: bricks
Date: 2017-09-29 14:32:53 +0200 (Fri, 29 Sep 2017)
New Revision: 29718

Added:
   trunk/gsa/src/html/classic/ng/src/web/entity/component.js
   trunk/gsa/src/html/classic/ng/src/web/pages/targets/component.js
Modified:
   trunk/gsa/ChangeLog
   trunk/gsa/src/html/classic/ng/CMakeLists.txt
Log:
* src/html/classic/ng/CMakeLists.txt,
src/html/classic/ng/src/web/entity/component.js,
src/html/classic/ng/src/web/pages/targets/component.js:: Provide reusable
components for entity and target specific access. These components are using
the "render props" pattern and should replace the with<entity type>Component
HOCs at the end (or at least make them easier to implement).

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2017-09-29 12:32:51 UTC (rev 29717)
+++ trunk/gsa/ChangeLog	2017-09-29 12:32:53 UTC (rev 29718)
@@ -1,5 +1,14 @@
 2017-09-29  Björn Ricks <bjoern.ricks@greenbone.net>
 
+	* src/html/classic/ng/CMakeLists.txt,
+	src/html/classic/ng/src/web/entity/component.js,
+	src/html/classic/ng/src/web/pages/targets/component.js:: Provide reusable
+	components for entity and target specific access. These components are using
+	the "render props" pattern and should replace the with<entity type>Component
+	HOCs at the end (or at least make them easier to implement).
+
+2017-09-29  Björn Ricks <bjoern.ricks@greenbone.net>
+
 	* src/html/classic/ng/src/web/pages/reports/emptyreport.js: Update message
 	when the report is empty.
 

Modified: trunk/gsa/src/html/classic/ng/CMakeLists.txt
===================================================================
--- trunk/gsa/src/html/classic/ng/CMakeLists.txt	2017-09-29 12:32:51 UTC (rev 29717)
+++ trunk/gsa/src/html/classic/ng/CMakeLists.txt	2017-09-29 12:32:53 UTC (rev 29718)
@@ -312,6 +312,7 @@
      ${NG_SRC_DIR}/src/web/entities/withRowDetails.js
      ${NG_SRC_DIR}/src/web/entity/block.js
      ${NG_SRC_DIR}/src/web/entity/box.js
+     ${NG_SRC_DIR}/src/web/entity/component.js
      ${NG_SRC_DIR}/src/web/entity/container.js
      ${NG_SRC_DIR}/src/web/entity/icon/cloneicon.js
      ${NG_SRC_DIR}/src/web/entity/icon/createicon.js
@@ -485,6 +486,7 @@
      ${NG_SRC_DIR}/src/web/pages/tags/dialog.js
      ${NG_SRC_DIR}/src/web/pages/tags/listpage.js
      ${NG_SRC_DIR}/src/web/pages/tags/row.js
+     ${NG_SRC_DIR}/src/web/pages/targets/component.js
      ${NG_SRC_DIR}/src/web/pages/targets/details.js
      ${NG_SRC_DIR}/src/web/pages/targets/detailspage.js
      ${NG_SRC_DIR}/src/web/pages/targets/dialogcontainer.js

Added: trunk/gsa/src/html/classic/ng/src/web/entity/component.js
===================================================================
--- trunk/gsa/src/html/classic/ng/src/web/entity/component.js	                        (rev 0)
+++ trunk/gsa/src/html/classic/ng/src/web/entity/component.js	2017-09-29 12:32:53 UTC (rev 29718)
@@ -0,0 +1,113 @@
+/* Greenbone Security Assistant
+ *
+ * Authors:
+ * Björn Ricks <bjoern.ricks@greenbone.net>
+ *
+ * Copyright:
+ * Copyright (C) 2017 Greenbone Networks GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+import React from 'react';
+
+import {is_defined} from 'gmp/utils.js';
+
+import PropTypes from '../utils/proptypes.js';
+
+import withContext from '../utils/withContext.js';
+
+class EntityComponent extends React.Component {
+
+  constructor(...args) {
+    super(...args);
+
+    this.handleEntityClone = this.handleEntityClone.bind(this);
+    this.handleEntityDelete = this.handleEntityDelete.bind(this);
+    this.handleEntityDownload = this.handleEntityDownload.bind(this);
+    this.handleEntitySave = this.handleEntitySave.bind(this);
+  }
+
+  handleEntityDelete(entity) {
+    const {onDeleted, onDeleteError, gmp, name} = this.props;
+    const cmd = gmp[name];
+    return cmd.delete(entity).then(onDeleted, onDeleteError);
+  }
+
+  handleEntityClone(entity) {
+    const {onCloned, onCloneError, gmp, name} = this.props;
+    const cmd = gmp[name];
+    return cmd.clone(entity).then(onCloned, onCloneError);
+  }
+
+  handleEntitySave(data) {
+    const {gmp, name} = this.props;
+    const cmd = gmp[name];
+
+    if (is_defined(data.id)) {
+      const {onSaved, onSaveError} = this.props;
+      return cmd.save(data).then(onSaved, onSaveError);
+    }
+
+    const {onCreated, onCreateError} = this.props;
+    return cmd.create(data).then(onCreated, onCreateError);
+  }
+
+  handleEntityDownload(entity) {
+    const {onDownloaded, onDownloadError, gmp, name} = this.props;
+    const cmd = gmp[name];
+
+    const promise = cmd.export(entity).then(response => {
+      const filename = name + '-' + entity.id + '.xml';
+      return {filename, data: response.data};
+    });
+
+    return promise.then(onDownloaded, onDownloadError);
+  }
+
+  render() {
+    const {children} = this.props;
+
+    return children({
+      create: this.handleEntitySave,
+      clone: this.handleEntityClone,
+      delete: this.handleEntityDelete,
+      save: this.handleEntitySave,
+      download: this.handleEntityDownload,
+    });
+  }
+}
+
+EntityComponent.propTypes = {
+  children: PropTypes.func.isRequired,
+  gmp: PropTypes.gmp.isRequired,
+  name: PropTypes.string.isRequired,
+  onCloneError: PropTypes.func,
+  onCloned: PropTypes.func,
+  onCreateError: PropTypes.func,
+  onCreated: PropTypes.func,
+  onDeleteError: PropTypes.func,
+  onDeleted: PropTypes.func,
+  onDownloadError: PropTypes.func,
+  onDownloaded: PropTypes.func,
+  onSaveError: PropTypes.func,
+  onSaved: PropTypes.func,
+};
+
+export default withContext({
+  gmp: PropTypes.gmp.isRequired,
+})(EntityComponent);
+
+// vim: set ts=2 sw=2 tw=80:

Added: trunk/gsa/src/html/classic/ng/src/web/pages/targets/component.js
===================================================================
--- trunk/gsa/src/html/classic/ng/src/web/pages/targets/component.js	                        (rev 0)
+++ trunk/gsa/src/html/classic/ng/src/web/pages/targets/component.js	2017-09-29 12:32:53 UTC (rev 29718)
@@ -0,0 +1,219 @@
+/* Greenbone Security Assistant
+ *
+ * Authors:
+ * Björn Ricks <bjoern.ricks@greenbone.net>
+ *
+ * Copyright:
+ * Copyright (C) 2016 - 2017 Greenbone Networks GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+import React from 'react';
+
+import _ from 'gmp/locale.js';
+import {first, is_defined} from 'gmp/utils.js';
+
+import PropTypes from '../../utils/proptypes.js';
+
+import Layout from '../../components/layout/layout.js';
+
+import EntityComponent from '../../entity/component.js';
+
+import CredentialsDialog from '../credentials/dialog.js';
+
+import PortListDialog from '../portlists/dialog.js';
+
+import TargetDialog from './dialog.js';
+
+const id_or__ = value => {
+  return is_defined(value) ? value.id : 0;
+};
+
+class TargetComponent extends React.Component {
+
+  constructor(...args) {
+    super(...args);
+
+    this.openCredentialsDialog = this.openCredentialsDialog.bind(this);
+    this.openPortListDialog = this.openPortListDialog.bind(this);
+    this.openTargetDialog = this.openTargetDialog.bind(this);
+    this.openCreateTargetDialog = this.openCreateTargetDialog.bind(this);
+    this.handleCreateCredential = this.handleCreateCredential.bind(this);
+    this.handleCreatePortList = this.handleCreatePortList.bind(this);
+  }
+
+  openCredentialsDialog(data) {
+    this.credentials_dialog.show({
+      types: data.types,
+      base: first(data.types),
+      id_field: data.id_field,
+    }, {
+      title: data.title,
+    });
+  }
+
+  openTargetDialog(entity) {
+    if (is_defined(entity)) {
+      this.target_dialog.show({
+        id: entity.id,
+        alive_tests: entity.alive_tests,
+        comment: entity.comment,
+        esxi_credential_id: id_or__(entity.esxi_credential),
+        exclude_hosts: is_defined(entity.exclude_hosts) ?
+          entity.exclude_hosts.join(', ') : '',
+        hosts: entity.hosts.join(', '),
+        in_use: entity.isInUse(),
+        name: entity.name,
+        port_list_id: id_or__(entity.port_list),
+        port: is_defined(entity.ssh_credential) ?
+          entity.ssh_credential.port : '22',
+        reverse_lookup_only: entity.reverse_lookup_only,
+        reverse_lookup_unify: entity.reverse_lookup_unify,
+        smb_credential_id: id_or__(entity.smb_credential),
+        snmp_credential_id: id_or__(entity.snmp_credential),
+        ssh_credential_id: id_or__(entity.ssh_credential),
+        target_source: 'manual',
+        target_exclude_source: 'manual',
+      }, {
+        title: _('Edit Target {{name}}', entity),
+      });
+
+      this.loadData();
+    }
+  }
+
+  openCreateTargetDialog(initial = {}) {
+    this.target_dialog.show(initial);
+
+    this.loadData();
+  }
+
+  loadData() {
+    const {gmp} = this.context;
+
+    gmp.portlists.getAll().then(port_lists => {
+      this.port_lists = port_lists;
+      this.target_dialog.setValues({port_lists});
+    });
+
+    gmp.credentials.getAll().then(credentials => {
+      this.credentials = credentials;
+      this.target_dialog.setValues({credentials});
+    });
+  }
+
+  openPortListDialog() {
+    this.port_list_dialog.show({});
+  }
+
+  handleCreateCredential(data) {
+    const {gmp} = this.context;
+    return gmp.credential.create(data).then(response => {
+      const credential = response.data;
+      const {credentials = []} = this;
+      credentials.push(credential);
+
+      this.target_dialog.setValues({
+        credentials,
+        [data.id_field]: credential.id,
+      });
+    });
+  }
+
+  handleCreatePortList(data) {
+    const {gmp} = this.context;
+    return gmp.portlist.create(data).then(response => {
+      const portlist = response.data;
+      const {port_lists = []} = this;
+      port_lists.push(portlist);
+      this.target_dialog.setValues({
+        port_lists,
+        port_list_id: portlist.id,
+      });
+    });
+  }
+
+  render() {
+    const {
+      children,
+      onCloned,
+      onCreated,
+      onDeleted,
+      onDeleteError,
+      onDownloaded,
+      onDownloadError,
+      onSaved,
+    } = this.props;
+    return (
+      <EntityComponent
+        name="target"
+        onCreated={onCreated}
+        onCloned={onCloned}
+        onDeleted={onDeleted}
+        onDeleteError={onDeleteError}
+        onDownloaded={onDownloaded}
+        onDownloadError={onDownloadError}
+        onSaved={onSaved}
+      >
+        {({
+          save,
+          ...other
+        }) => (
+          <Layout>
+            {children({
+              ...other,
+              create: this.openCreateTargetDialog,
+              edit: this.openTargetDialog,
+            })}
+            <TargetDialog
+              ref={ref => this.target_dialog = ref}
+              onNewCredentialsClick={this.openCredentialsDialog}
+              onNewPortListClick={this.openPortListDialog}
+              onSave={save}
+            />
+            <CredentialsDialog
+              ref={ref => this.credentials_dialog = ref}
+              onSave={this.handleCreateCredential}
+            />
+            <PortListDialog
+              ref={ref => this.port_list_dialog = ref}
+              onSave={this.handleCreatePortList}
+            />
+          </Layout>
+        )}
+      </EntityComponent>
+    );
+  }
+};
+
+TargetComponent.propTypes = {
+  children: PropTypes.func.isRequired,
+  onCloned: PropTypes.func,
+  onCreated: PropTypes.func,
+  onDeleteError: PropTypes.func,
+  onDeleted: PropTypes.func,
+  onDownloadError: PropTypes.func,
+  onDownloaded: PropTypes.func,
+  onSaved: PropTypes.func,
+};
+
+TargetComponent.contextTypes = {
+  gmp: PropTypes.gmp.isRequired,
+};
+
+export default TargetComponent;
+
+// vim: set ts=2 sw=2 tw=80:



_______________________________________________
Openvas-commits mailing list
Openvas-commits@wald.intevation.org
https://lists.wald.intevation.org/cgi-bin/mailman/listinfo/openvas-commits

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic