Browse Source

Merge pull request #1326 from mertmit/add-url-formula

feat: add URL formula
pull/1345/head
աɨռɢӄաօռɢ 3 years ago committed by GitHub
parent
commit
c3070e609d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/formulaCell.vue
  2. 1
      packages/nc-gui/helpers/formulaList.js
  3. 26
      packages/nocodb/src/lib/dataMapper/lib/sql/formulaQueryBuilderFromString.ts

19
packages/nc-gui/components/project/spreadsheet/components/virtualCell/formulaCell.vue

@ -9,6 +9,7 @@
</template>
<span class=" font-weight-bold">{{ column.formula.error.join(', ') }}</span>
</v-tooltip>
<div v-else-if="urls" v-html="urls"></div>
<div v-else>
{{ row[column._cn] }}
</div>
@ -17,7 +18,23 @@
<script>
export default {
name: 'FormulaCell',
props: ['column', 'row']
props: ['column', 'row'],
computed: {
urls: function() {
if(this.row[this.column._cn] ) {
let rawText = this.row[this.column._cn].toString();
let matchURLs = rawText.match(/URI::\((.*?)\)/g);
if(matchURLs) {
for(const url of matchURLs) {
let tmpuri = url.match(/URI::\((.*?)\)/)[1];
rawText = rawText.replace(url, '<a href="' + tmpuri + '" target="_blank">' + tmpuri + '</a>');
}
return rawText;
}
}
return false;
}
}
}
</script>

1
packages/nc-gui/helpers/formulaList.js

@ -54,6 +54,7 @@ const validations = {
MID: { validation: { args: { rqd: 1 } } },
IF: { validation: { args: { min: 2, max: 3 } } },
SWITCH: { validation: { args: { min: 3 } } },
URL: { validation: { args: { rqd: 1 } } },
};
export default Object.keys(validations);

26
packages/nocodb/src/lib/dataMapper/lib/sql/formulaQueryBuilderFromString.ts

@ -64,6 +64,32 @@ export default function formulaQueryBuilder(
}
}
break;
case 'URL':
return fn(
{
type: 'CallExpression',
arguments: [
{
type: 'Literal',
value: 'URI::(',
raw: '"URI::("'
},
pt.arguments[0],
{
type: 'Literal',
value: ')',
raw: '")"'
}
],
callee: {
type: 'Identifier',
name: 'CONCAT'
}
},
a,
prevBinaryOp
);
break;
default:
{
const res = mapFunctionName({

Loading…
Cancel
Save