From 9fd5bad4220179f1eb6c6e5b0400fac959e79aae Mon Sep 17 00:00:00 2001 From: Daniel Ruf Date: Thu, 7 Jun 2018 13:36:50 +0200 Subject: [PATCH 01/10] chore: cache dependencies --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 23c1a181ee..19f347a9e8 100755 --- a/.travis.yml +++ b/.travis.yml @@ -22,3 +22,8 @@ install: script: - npm run doc + - npm run test + +cache: + directories: + - "node_modules" From 5a54d7c2a2254bd5ef5cb1844693638e89fa2306 Mon Sep 17 00:00:00 2001 From: Daniel Ruf Date: Sat, 30 Jun 2018 17:49:38 +0200 Subject: [PATCH 02/10] fix: Do not cleanup directories --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 19f347a9e8..f2486aa99c 100755 --- a/.travis.yml +++ b/.travis.yml @@ -13,16 +13,15 @@ before_install: - export CHROME_BIN=chromium-browser - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start - - sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share} - - npm cache clean --force - - rm -rf node_modules/ + # - sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share} + # - npm cache clean --force + # - rm -rf node_modules/ install: - npm run setup --debug script: - npm run doc - - npm run test cache: directories: From 5c5ca6818c18a73f45c95008d9c9c1551b7f2a49 Mon Sep 17 00:00:00 2001 From: Daniel Ruf Date: Sat, 30 Jun 2018 18:15:30 +0200 Subject: [PATCH 03/10] chore: trigger new build From bc7f210771043d0fea14cce59ff27618a1799234 Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Wed, 4 Jul 2018 16:20:44 +0200 Subject: [PATCH 04/10] Improve SQL table creation/update performance --- packages/strapi-bookshelf/lib/index.js | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/strapi-bookshelf/lib/index.js b/packages/strapi-bookshelf/lib/index.js index cec982670c..3e5292ecbf 100755 --- a/packages/strapi-bookshelf/lib/index.js +++ b/packages/strapi-bookshelf/lib/index.js @@ -501,6 +501,25 @@ module.exports = function(strapi) { } }; + const storeTable = async (table, attributes) => { + const existTable = await StrapiConfigs.forge({key: `db_model_${table}`}).fetch(); + + if (existTable) { + await StrapiConfigs.forge({id: existTable.id}).save({ + value: attributes + }, { + path: true + }); + } else { + await StrapiConfigs.forge({ + key: `db_model_${table}`, + type: 'object', + value: attributes + }).save(); + } + }; + + if (!tableExist) { const columns = generateColumns(attributes, [`id ${definition.client === 'pg' ? 'SERIAL' : 'INT AUTO_INCREMENT'} NOT NULL PRIMARY KEY`]).join(',\n\r'); @@ -513,7 +532,10 @@ module.exports = function(strapi) { // Generate indexes. await generateIndexes(table, attributes); + + await storeTable(table, attributes); } else { + const columns = Object.keys(attributes); // Fetch existing column @@ -546,9 +568,21 @@ module.exports = function(strapi) { await Promise.all(queries.map(query => ORM.knex.raw(query))); } + let previousAttributes; + try { + previousAttributes = JSON.parse((await StrapiConfigs.forge({key: `db_model_${table}`}).fetch()).toJSON().value); + } catch (err) { + await storeTable(table, attributes); + previousAttributes = JSON.parse((await StrapiConfigs.forge({key: `db_model_${table}`}).fetch()).toJSON().value); + } + // Execute query to update column type await Promise.all(columns.map(attribute => new Promise(async (resolve) => { + if (JSON.stringify(previousAttributes[attribute]) === JSON.stringify(attributes[attribute])) { + return resolve(); + } + const type = getType(attributes[attribute], attribute); if (type) { @@ -567,6 +601,8 @@ module.exports = function(strapi) { resolve(); }) )); + + await storeTable(table, attributes); } }; From d17def7a128589dfaefc6bc7323638d92312bad5 Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Wed, 4 Jul 2018 17:23:04 +0200 Subject: [PATCH 05/10] Add options to disable auto table/column creation --- docs/3.x.x/en/configurations/configurations.md | 3 +++ packages/strapi-bookshelf/lib/index.js | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/3.x.x/en/configurations/configurations.md b/docs/3.x.x/en/configurations/configurations.md index c9f8eab486..f037ab6c59 100644 --- a/docs/3.x.x/en/configurations/configurations.md +++ b/docs/3.x.x/en/configurations/configurations.md @@ -179,6 +179,9 @@ Most of the application's configurations are defined by environment. It means th - `password` (string): Password used to establish the connection. - `options` (object): List of additional options used by the connector. - `timezone` (string): Set the default behavior for local time (used only for a SQL database). Default value: `utc`. + - `options` Options used for database connection. + - `ssl` (boolean): For ssl database connection. + - `autoMigration` (boolean): To disable auto tables/columns creation for SQL database. #### Example diff --git a/packages/strapi-bookshelf/lib/index.js b/packages/strapi-bookshelf/lib/index.js index 3e5292ecbf..e739d99a82 100755 --- a/packages/strapi-bookshelf/lib/index.js +++ b/packages/strapi-bookshelf/lib/index.js @@ -619,7 +619,9 @@ module.exports = function(strapi) { } // Equilize tables - await handler(loadedModel.tableName, definition.attributes); + if (connection.options && connection.options.autoMigration !== false) { + await handler(loadedModel.tableName, definition.attributes); + } // Equilize polymorphic releations const morphRelations = definition.associations.find((association) => { @@ -642,7 +644,9 @@ module.exports = function(strapi) { } }; - await handler(`${loadedModel.tableName}_morph`, attributes); + if (connection.options && connection.options.autoMigration !== false) { + await handler(`${loadedModel.tableName}_morph`, attributes); + } } // Equilize many to many releations From 6203bdc200a50fb9e1dcc56494d4c640c4f2fced Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Wed, 4 Jul 2018 18:08:42 +0200 Subject: [PATCH 06/10] Fix json store object --- packages/strapi-bookshelf/lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/strapi-bookshelf/lib/index.js b/packages/strapi-bookshelf/lib/index.js index e739d99a82..d73418eba4 100755 --- a/packages/strapi-bookshelf/lib/index.js +++ b/packages/strapi-bookshelf/lib/index.js @@ -506,7 +506,7 @@ module.exports = function(strapi) { if (existTable) { await StrapiConfigs.forge({id: existTable.id}).save({ - value: attributes + value: JSON.stringify(attributes) }, { path: true }); @@ -514,7 +514,7 @@ module.exports = function(strapi) { await StrapiConfigs.forge({ key: `db_model_${table}`, type: 'object', - value: attributes + value: JSON.stringify(attributes) }).save(); } }; From a09eead62505cdd6aa0aa8817708bdf16631c670 Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Wed, 4 Jul 2018 18:33:50 +0200 Subject: [PATCH 07/10] Add debug option in doc --- docs/3.x.x/en/configurations/configurations.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/3.x.x/en/configurations/configurations.md b/docs/3.x.x/en/configurations/configurations.md index f037ab6c59..d038fc99ec 100644 --- a/docs/3.x.x/en/configurations/configurations.md +++ b/docs/3.x.x/en/configurations/configurations.md @@ -181,6 +181,7 @@ Most of the application's configurations are defined by environment. It means th - `timezone` (string): Set the default behavior for local time (used only for a SQL database). Default value: `utc`. - `options` Options used for database connection. - `ssl` (boolean): For ssl database connection. + - `debug` (boolean): Show database exchanges and errors. - `autoMigration` (boolean): To disable auto tables/columns creation for SQL database. #### Example From d319d22f91c13a7071abba9db68fc95a20e3ccfc Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Fri, 6 Jul 2018 14:15:59 +0200 Subject: [PATCH 08/10] Fixes #1518 --- .../lib/src/components/ImgPreview/index.js | 12 ++++++++---- .../lib/src/components/PageFooter/index.js | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/strapi-helper-plugin/lib/src/components/ImgPreview/index.js b/packages/strapi-helper-plugin/lib/src/components/ImgPreview/index.js index 8162593d31..197af53f44 100644 --- a/packages/strapi-helper-plugin/lib/src/components/ImgPreview/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/ImgPreview/index.js @@ -8,7 +8,7 @@ /* eslint-disable no-console */ import React from 'react'; import PropTypes from 'prop-types'; -import { get, has, isArray, isEmpty, size } from 'lodash'; +import { get, has, isArray, isEmpty, startsWith, size } from 'lodash'; import cn from 'classnames'; import BkgImg from 'assets/icons/icon_upload.svg'; @@ -31,9 +31,10 @@ class ImgPreview extends React.Component { componentDidMount() { // We don't need the generateImgURL function here since the compo will // always have an init value here + const file = this.props.multiple ? get(this.props.files, ['0', 'name'], '') : get(this.props.files, 'name'); this.setState({ imgURL: get(this.props.files, ['0', 'url'], '') || get(this.props.files, 'url', ''), - isImg: this.isPictureType(get(this.props.files, ['0', 'name'], '')), + isImg: this.isPictureType(file), }); } @@ -142,10 +143,12 @@ class ImgPreview extends React.Component { renderContent = () => { const fileType = this.getFileType(this.state.imgURL); - + if (this.state.isImg) { + const imgURL = startsWith(this.state.imgURL, '/') ? `${strapi.backendURL}${this.state.imgURL}` : this.state.imgURL; + return ( - + ); } @@ -159,6 +162,7 @@ class ImgPreview extends React.Component { render() { const { files, onBrowseClick } = this.props; const { imgURL } = this.state; + const containerStyle = isEmpty(imgURL) ? { backgroundImage: `url(${BkgImg})`, diff --git a/packages/strapi-helper-plugin/lib/src/components/PageFooter/index.js b/packages/strapi-helper-plugin/lib/src/components/PageFooter/index.js index 898adbf6de..56053b72a4 100644 --- a/packages/strapi-helper-plugin/lib/src/components/PageFooter/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/PageFooter/index.js @@ -14,6 +14,7 @@ import GlobalPagination from 'components/GlobalPagination'; import styles from './styles.scss'; +/* eslint-disable jsx-a11y/label-has-for */ function PageFooter(props) { return (
From 3f6da374cb0f8a643b380198a9016bfc0228a947 Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Fri, 6 Jul 2018 14:39:18 +0200 Subject: [PATCH 09/10] Fixes #1387 #1374 --- .../admin/src/containers/Form/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/index.js index b7ad4851b5..c0513dfa95 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/index.js @@ -143,7 +143,8 @@ export class Form extends React.Component { // eslint-disable-line react/prefer- } // Check if user is adding a relation with the same content type - if (includes(this.props.hash, 'attributerelation') && this.props.modifiedDataAttribute.params.target === this.props.modelName) { + + if (includes(this.props.hash, 'attributerelation') && this.props.modifiedDataAttribute.params.target === this.props.modelName && get(this.props.modifiedDataAttribute, ['params', 'nature'], '') !== 'oneWay') { // Insert two attributes this.props.addAttributeRelationToContentType(this.props.modifiedDataAttribute); } else { @@ -168,7 +169,8 @@ export class Form extends React.Component { // eslint-disable-line react/prefer- const contentType = this.props.modifiedDataEdit; // Add the new attribute to the content type attribute list const newAttribute = this.setTempAttribute(); - contentType.attributes = compact(concat(contentType.attributes, newAttribute, this.setParallelAttribute(newAttribute))); + const parallelAttribute = this.props.modelName === get(newAttribute, ['params', 'target']) && get(newAttribute, ['params', 'nature'], '') === 'oneWay' ? null : this.setParallelAttribute(newAttribute); + contentType.attributes = compact(concat(contentType.attributes, newAttribute, parallelAttribute)); // Reset the store and update the parent container this.props.contentTypeCreate(contentType); // Get the displayed model from the localStorage From f8b6edb23f64247f29d4c3d6cd3fe076aba063c4 Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Mon, 9 Jul 2018 14:04:20 +0200 Subject: [PATCH 10/10] Fix display with onWay relation --- .../admin/src/components/PopUpRelations/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/PopUpRelations/index.js b/packages/strapi-plugin-content-type-builder/admin/src/components/PopUpRelations/index.js index e7f81ab9b0..2061ac395b 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/components/PopUpRelations/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/components/PopUpRelations/index.js @@ -123,8 +123,9 @@ class PopUpRelations extends React.Component { value[0], ); } else { + const keyValue = get(this.props.values, 'params.nature') === 'oneWay' ? '-' : ''; this.props.onChange({ target: { name: 'name', value: '' } }); - this.props.onChange({ target: { name: 'params.key', value: '' } }); + this.props.onChange({ target: { name: 'params.key', value: keyValue } }); } } }; @@ -237,6 +238,8 @@ class PopUpRelations extends React.Component { const errs = findIndex(this.props.formErrors, ['name',get(this.props.form, ['items', '0', 'name'])]) !== -1 ? this.props.formErrors[findIndex(this.props.formErrors, ['name', get(this.props.form, ['items', '0', 'name'])])].errors: []; const errors = findIndex(this.props.formErrors, ['name', get(this.props.form, ['items', '1', 'name'])]) !== -1 ? this.props.formErrors[findIndex(this.props.formErrors, ['name', get(this.props.form, ['items', '1', 'name'])])].errors : []; + const contentTypeTargetPlaceholder = get(this.props.values, 'params.nature', '') === 'oneWay' ? '-' : get(this.props.contentType, 'name'); + const contentTypeTargetValue = get(this.props.values, 'params.nature') === 'oneWay' ? '-' : get(this.props.values, ['params', 'key']); return ( @@ -262,12 +265,12 @@ class PopUpRelations extends React.Component { />