diff --git a/public/js/databases.js b/public/js/databases.js index d83b7b87..a5d75886 100644 --- a/public/js/databases.js +++ b/public/js/databases.js @@ -6,20 +6,11 @@ export class Databases extends Component { super(props); this.state = { type: '' }; this.preSelectedDbs = this.props.preSelectedDbs; - this.databases = this.databases.bind(this); - this.nselected = this.nselected.bind(this); - this.categories = this.categories.bind(this); - this.handleClick = this.handleClick.bind(this); - this.handleToggle = this.handleToggle.bind(this); - this.renderDatabases = this.renderDatabases.bind(this); - this.renderDatabase = this.renderDatabase.bind(this); + this.updateDatabaseType = this.updateDatabaseType.bind(this); + this.getCategories = this.getCategories.bind(this); } - componentDidUpdate() { - if (this.databases() && this.databases().length === 1) { - $('.databases').find('input').prop('checked', true); - this.handleClick(this.databases()[0]); - } + componentDidUpdate() { if (this.preSelectedDbs) { var selectors = this.preSelectedDbs.map((db) => `input[value=${db.id}]`); $(selectors.join(',')).prop('checked', true); @@ -28,8 +19,58 @@ export class Databases extends Component { } this.props.onDatabaseTypeChanged(this.state.type); } - databases(category) { - var databases = this.props.databases; + + getCategories() { + return _.uniq(_.map(this.props.databases, _.iteratee('type'))).sort(); + } + + updateDatabaseType (type) { + if (type != this.state.type) this.setState({ type }); + + } + + render() { + return ( +
+ {_.map(this.getCategories(), (category) =>( + + ))} +
+ ); + } +} + +export class DatabaseCategory extends Component { + constructor(props) { + super(props); + this.state = { allSelected: false, selectedDbs: [] }; + this.databases = this.props.databases; + this.category = this.props.category; + this.getCategories = this.props.getCategories; + this.getDatabases = this.getDatabases.bind(this); + this.nselected = this.nselected.bind(this); + this.handleClick = this.handleClick.bind(this); + this.handleToggle = this.handleToggle.bind(this); + this.renderPanelHeading = this.renderPanelHeading.bind(this); + this.renderDatabase = this.renderDatabase.bind(this); + + } + componentDidUpdate() { + // SELECT DATABASE by default if only one is present + if (this.getDatabases() && this.getDatabases().length === 1) { + $('.databases').find('input').prop('checked', true); + this.handleClick(this.getDatabases()[0]); + } + } + getDatabases(category) { + var databases = this.databases; if (category) { databases = _.select(databases, (database) => database.type === category); } @@ -41,67 +82,96 @@ export class Databases extends Component { return $('input[name="databases[]"]:checked').length; } - categories() { - return _.uniq(_.map(this.props.databases, _.iteratee('type'))).sort(); - } + handleClick(checked, database, category) { + const getSelectedDbs = (currentState) => + checked + ? currentState.selectedDbs.concat([database.id]) + : currentState.selectedDbs.filter((db) => db !== database.id); - handleClick(database) { + this.setState( + (prevState) => ({ + selectedDbs: getSelectedDbs(prevState), + allSelected: + getSelectedDbs(prevState).length === this.getDatabases(category).length, + }) + ); var type = this.nselected() ? database.type : ''; - if (type != this.state.type) this.setState({ type: type }); + this.props.updateDatabaseType(type); } - handleToggle(toggleState, type) { - switch (toggleState) { - case '[Select all]': - $(`.${type} .database input:not(:checked)`).click(); - break; - case '[Deselect all]': - $(`.${type} .database input:checked`).click(); - break; - } - this.forceUpdate(); + handleToggle(type) { + this.state.allSelected + ? $(`.${type} .database input:checked`).click() + : $(`.${type} .database input:not(:checked)`).click(); } - renderDatabases(category) { - // Panel name and column width. - var panelTitle = category[0].toUpperCase() + category.substring(1).toLowerCase() + ' databases'; - var columnClass = this.categories().length === 1 ? 'col-md-12' : 'col-md-6'; + renderDatabase(database){ + var disabled = this.props.type && this.props.type !== database.type; + + return ( + + ); + } + + renderPanelHeading(){ + // Panel name and column width. + var panelTitle = + this.category[0].toUpperCase() + + this.category.substring(1).toLowerCase() + + ' databases'; // Toggle button. - var toggleState = '[Select all]'; + var toggleState = + this.state.allSelected ? '[Deselect all]' : '[Select all]'; var toggleClass = 'btn-link'; - var toggleShown = this.databases(category).length > 1; - var toggleDisabled = this.state.type && this.state.type !== category; + var toggleShown = this.getDatabases(this.category).length > 1; + var toggleDisabled = this.props.type && this.props.type !== this.category; if (toggleShown && toggleDisabled) toggleClass += ' disabled'; if (!toggleShown) toggleClass += ' hidden'; - if (this.nselected() === this.databases(category).length) { - toggleState = '[Deselect all]'; - } + return ( +
+

{panelTitle}

   + +
); + } + + render() { + var columnClass = this.getCategories().length === 1 ? 'col-md-12' : 'col-md-6'; // JSX. return ( -
+
-
-

{panelTitle}

   - -
-
    + {this.renderPanelHeading()} +
      {_.map( - this.databases(category), + this.getDatabases(this.category), _.bind(function (database, index) { return (
    • {this.renderDatabase(database)}
    • @@ -114,31 +184,4 @@ export class Databases extends Component { ); } - renderDatabase(database) { - var disabled = this.state.type && this.state.type !== database.type; - - return ( - - ); - } - - render() { - return ( -
      - {_.map(this.categories(), this.renderDatabases)} -
      - ); - } } \ No newline at end of file diff --git a/public/sequenceserver-search.min.js b/public/sequenceserver-search.min.js index 7b2efa11..e21188f6 100644 --- a/public/sequenceserver-search.min.js +++ b/public/sequenceserver-search.min.js @@ -16,7 +16,7 @@ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Databases\": () => (/* binding */ Databases)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ \"./node_modules/underscore/modules/index-all.js\");\n/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react/jsx-runtime */ \"./node_modules/react/jsx-runtime.js\");\n/* provided dependency */ var $ = __webpack_require__(/*! jquery */ \"./node_modules/jquery/dist/jquery.js\");\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && \"function\" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }, _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, \"prototype\", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } else if (call !== void 0) { throw new TypeError(\"Derived constructors may only return object or undefined\"); } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\n\n\n\n\nvar Databases = /*#__PURE__*/function (_Component) {\n _inherits(Databases, _Component);\n\n var _super = _createSuper(Databases);\n\n function Databases(props) {\n var _this;\n\n _classCallCheck(this, Databases);\n\n _this = _super.call(this, props);\n _this.state = {\n type: ''\n };\n _this.preSelectedDbs = _this.props.preSelectedDbs;\n _this.databases = _this.databases.bind(_assertThisInitialized(_this));\n _this.nselected = _this.nselected.bind(_assertThisInitialized(_this));\n _this.categories = _this.categories.bind(_assertThisInitialized(_this));\n _this.handleClick = _this.handleClick.bind(_assertThisInitialized(_this));\n _this.handleToggle = _this.handleToggle.bind(_assertThisInitialized(_this));\n _this.renderDatabases = _this.renderDatabases.bind(_assertThisInitialized(_this));\n _this.renderDatabase = _this.renderDatabase.bind(_assertThisInitialized(_this));\n return _this;\n }\n\n _createClass(Databases, [{\n key: \"componentDidUpdate\",\n value: function componentDidUpdate() {\n if (this.databases() && this.databases().length === 1) {\n $('.databases').find('input').prop('checked', true);\n this.handleClick(this.databases()[0]);\n }\n\n if (this.preSelectedDbs) {\n var selectors = this.preSelectedDbs.map(function (db) {\n return \"input[value=\".concat(db.id, \"]\");\n });\n $(selectors.join(',')).prop('checked', true);\n this.handleClick(this.preSelectedDbs[0]);\n this.preSelectedDbs = null;\n }\n\n this.props.onDatabaseTypeChanged(this.state.type);\n }\n }, {\n key: \"databases\",\n value: function databases(category) {\n var databases = this.props.databases;\n\n if (category) {\n databases = underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].select(databases, function (database) {\n return database.type === category;\n });\n }\n\n return underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].sortBy(databases, 'title');\n }\n }, {\n key: \"nselected\",\n value: function nselected() {\n return $('input[name=\"databases[]\"]:checked').length;\n }\n }, {\n key: \"categories\",\n value: function categories() {\n return underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].uniq(underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].map(this.props.databases, underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].iteratee('type'))).sort();\n }\n }, {\n key: \"handleClick\",\n value: function handleClick(database) {\n var type = this.nselected() ? database.type : '';\n if (type != this.state.type) this.setState({\n type: type\n });\n }\n }, {\n key: \"handleToggle\",\n value: function handleToggle(toggleState, type) {\n switch (toggleState) {\n case '[Select all]':\n $(\".\".concat(type, \" .database input:not(:checked)\")).click();\n break;\n\n case '[Deselect all]':\n $(\".\".concat(type, \" .database input:checked\")).click();\n break;\n }\n\n this.forceUpdate();\n }\n }, {\n key: \"renderDatabases\",\n value: function renderDatabases(category) {\n // Panel name and column width.\n var panelTitle = category[0].toUpperCase() + category.substring(1).toLowerCase() + ' databases';\n var columnClass = this.categories().length === 1 ? 'col-md-12' : 'col-md-6'; // Toggle button.\n\n var toggleState = '[Select all]';\n var toggleClass = 'btn-link';\n var toggleShown = this.databases(category).length > 1;\n var toggleDisabled = this.state.type && this.state.type !== category;\n if (toggleShown && toggleDisabled) toggleClass += ' disabled';\n if (!toggleShown) toggleClass += ' hidden';\n\n if (this.nselected() === this.databases(category).length) {\n toggleState = '[Deselect all]';\n } // JSX.\n\n\n return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"div\", {\n className: columnClass,\n children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsxs)(\"div\", {\n className: \"panel panel-default\",\n children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsxs)(\"div\", {\n className: \"panel-heading\",\n children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"h4\", {\n style: {\n display: 'inline'\n },\n children: panelTitle\n }), \" \\xA0\\xA0\", /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"button\", {\n type: \"button\",\n className: toggleClass,\n disabled: toggleDisabled,\n onClick: function () {\n this.handleToggle(toggleState, category);\n }.bind(this),\n children: toggleState\n })]\n }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"ul\", {\n className: 'list-group databases ' + category,\n children: underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].map(this.databases(category), underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].bind(function (database, index) {\n return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"li\", {\n className: \"list-group-item\",\n children: this.renderDatabase(database)\n }, 'DB_' + category + index);\n }, this))\n })]\n })\n }, 'DB_' + category);\n }\n }, {\n key: \"renderDatabase\",\n value: function renderDatabase(database) {\n var disabled = this.state.type && this.state.type !== database.type;\n return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsxs)(\"label\", {\n className: disabled && 'disabled database' || 'database',\n children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"input\", {\n type: \"checkbox\",\n name: \"databases[]\",\n value: database.id,\n \"data-type\": database.type,\n disabled: disabled,\n onChange: underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].bind(function () {\n this.handleClick(database);\n }, this)\n }), ' ' + (database.title || database.name)]\n });\n }\n }, {\n key: \"render\",\n value: function render() {\n return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"div\", {\n className: \"form-group databases-container\",\n children: underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].map(this.categories(), this.renderDatabases)\n });\n }\n }]);\n\n return Databases;\n}(react__WEBPACK_IMPORTED_MODULE_0__.Component);\n\n//# sourceURL=webpack://SequenceServer/./public/js/databases.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"DatabaseCategory\": () => (/* binding */ DatabaseCategory),\n/* harmony export */ \"Databases\": () => (/* binding */ Databases)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ \"./node_modules/underscore/modules/index-all.js\");\n/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react/jsx-runtime */ \"./node_modules/react/jsx-runtime.js\");\n/* provided dependency */ var $ = __webpack_require__(/*! jquery */ \"./node_modules/jquery/dist/jquery.js\");\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && \"function\" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }, _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, \"prototype\", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } else if (call !== void 0) { throw new TypeError(\"Derived constructors may only return object or undefined\"); } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\n\n\n\n\nvar Databases = /*#__PURE__*/function (_Component) {\n _inherits(Databases, _Component);\n\n var _super = _createSuper(Databases);\n\n function Databases(props) {\n var _this;\n\n _classCallCheck(this, Databases);\n\n _this = _super.call(this, props);\n _this.state = {\n type: ''\n };\n _this.preSelectedDbs = _this.props.preSelectedDbs;\n _this.updateDatabaseType = _this.updateDatabaseType.bind(_assertThisInitialized(_this));\n _this.getCategories = _this.getCategories.bind(_assertThisInitialized(_this));\n return _this;\n }\n\n _createClass(Databases, [{\n key: \"componentDidUpdate\",\n value: function componentDidUpdate() {\n if (this.preSelectedDbs) {\n var selectors = this.preSelectedDbs.map(function (db) {\n return \"input[value=\".concat(db.id, \"]\");\n });\n $(selectors.join(',')).prop('checked', true);\n this.handleClick(this.preSelectedDbs[0]);\n this.preSelectedDbs = null;\n }\n\n this.props.onDatabaseTypeChanged(this.state.type);\n }\n }, {\n key: \"getCategories\",\n value: function getCategories() {\n return underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].uniq(underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].map(this.props.databases, underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].iteratee('type'))).sort();\n }\n }, {\n key: \"updateDatabaseType\",\n value: function updateDatabaseType(type) {\n if (type != this.state.type) this.setState({\n type: type\n });\n }\n }, {\n key: \"render\",\n value: function render() {\n var _this2 = this;\n\n return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"div\", {\n className: \"form-group databases-container\",\n children: underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].map(this.getCategories(), function (category) {\n return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(DatabaseCategory, {\n type: _this2.state.type,\n databases: _this2.props.databases,\n updateDatabaseType: _this2.updateDatabaseType,\n category: category,\n getCategories: _this2.getCategories\n }, category);\n })\n });\n }\n }]);\n\n return Databases;\n}(react__WEBPACK_IMPORTED_MODULE_0__.Component);\nvar DatabaseCategory = /*#__PURE__*/function (_Component2) {\n _inherits(DatabaseCategory, _Component2);\n\n var _super2 = _createSuper(DatabaseCategory);\n\n function DatabaseCategory(props) {\n var _this3;\n\n _classCallCheck(this, DatabaseCategory);\n\n _this3 = _super2.call(this, props);\n _this3.state = {\n allSelected: false,\n selectedDbs: []\n };\n _this3.databases = _this3.props.databases;\n _this3.category = _this3.props.category;\n _this3.getCategories = _this3.props.getCategories;\n _this3.getDatabases = _this3.getDatabases.bind(_assertThisInitialized(_this3));\n _this3.nselected = _this3.nselected.bind(_assertThisInitialized(_this3));\n _this3.handleClick = _this3.handleClick.bind(_assertThisInitialized(_this3));\n _this3.handleToggle = _this3.handleToggle.bind(_assertThisInitialized(_this3));\n _this3.renderPanelHeading = _this3.renderPanelHeading.bind(_assertThisInitialized(_this3));\n _this3.renderDatabase = _this3.renderDatabase.bind(_assertThisInitialized(_this3));\n return _this3;\n }\n\n _createClass(DatabaseCategory, [{\n key: \"componentDidUpdate\",\n value: function componentDidUpdate() {\n // SELECT DATABASE by default if only one is present\n if (this.getDatabases() && this.getDatabases().length === 1) {\n $('.databases').find('input').prop('checked', true);\n this.handleClick(this.getDatabases()[0]);\n }\n }\n }, {\n key: \"getDatabases\",\n value: function getDatabases(category) {\n var databases = this.databases;\n\n if (category) {\n databases = underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].select(databases, function (database) {\n return database.type === category;\n });\n }\n\n return underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].sortBy(databases, 'title');\n }\n }, {\n key: \"nselected\",\n value: function nselected() {\n return $('input[name=\"databases[]\"]:checked').length;\n }\n }, {\n key: \"handleClick\",\n value: function handleClick(checked, database, category) {\n var _this4 = this;\n\n var getSelectedDbs = function getSelectedDbs(currentState) {\n return checked ? currentState.selectedDbs.concat([database.id]) : currentState.selectedDbs.filter(function (db) {\n return db !== database.id;\n });\n };\n\n this.setState(function (prevState) {\n return {\n selectedDbs: getSelectedDbs(prevState),\n allSelected: getSelectedDbs(prevState).length === _this4.getDatabases(category).length\n };\n });\n var type = this.nselected() ? database.type : '';\n this.props.updateDatabaseType(type);\n }\n }, {\n key: \"handleToggle\",\n value: function handleToggle(type) {\n this.state.allSelected ? $(\".\".concat(type, \" .database input:checked\")).click() : $(\".\".concat(type, \" .database input:not(:checked)\")).click();\n }\n }, {\n key: \"renderDatabase\",\n value: function renderDatabase(database) {\n var disabled = this.props.type && this.props.type !== database.type;\n return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsxs)(\"label\", {\n className: disabled && 'disabled database' || 'database',\n children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"input\", {\n type: \"checkbox\",\n name: \"databases[]\",\n value: database.id,\n \"data-type\": database.type,\n disabled: disabled,\n checked: this.state.selectedDbs.includes(database.id),\n onChange: underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].bind(function (evt) {\n this.handleClick(evt.target.checked, database, this.category);\n }, this)\n }), ' ' + (database.title || database.name)]\n });\n }\n }, {\n key: \"renderPanelHeading\",\n value: function renderPanelHeading() {\n // Panel name and column width.\n var panelTitle = this.category[0].toUpperCase() + this.category.substring(1).toLowerCase() + ' databases'; // Toggle button.\n\n var toggleState = this.state.allSelected ? '[Deselect all]' : '[Select all]';\n var toggleClass = 'btn-link';\n var toggleShown = this.getDatabases(this.category).length > 1;\n var toggleDisabled = this.props.type && this.props.type !== this.category;\n if (toggleShown && toggleDisabled) toggleClass += ' disabled';\n if (!toggleShown) toggleClass += ' hidden';\n return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsxs)(\"div\", {\n className: \"panel-heading\",\n children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"h4\", {\n style: {\n display: 'inline'\n },\n children: panelTitle\n }), \" \\xA0\\xA0\", /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"button\", {\n type: \"button\",\n className: toggleClass,\n disabled: toggleDisabled,\n onClick: function () {\n this.handleToggle(this.category);\n }.bind(this),\n children: toggleState\n })]\n });\n }\n }, {\n key: \"render\",\n value: function render() {\n var columnClass = this.getCategories().length === 1 ? 'col-md-12' : 'col-md-6'; // JSX.\n\n return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"div\", {\n className: columnClass,\n children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsxs)(\"div\", {\n className: \"panel panel-default\",\n children: [this.renderPanelHeading(), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"ul\", {\n className: 'list-group databases ' + this.category,\n children: underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].map(this.getDatabases(this.category), underscore__WEBPACK_IMPORTED_MODULE_1__[\"default\"].bind(function (database, index) {\n return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)(\"li\", {\n className: \"list-group-item\",\n children: this.renderDatabase(database)\n }, 'DB_' + this.category + index);\n }, this))\n })]\n })\n }, 'DB_' + this.category);\n }\n }]);\n\n return DatabaseCategory;\n}(react__WEBPACK_IMPORTED_MODULE_0__.Component);\n\n//# sourceURL=webpack://SequenceServer/./public/js/databases.js?"); /***/ }),