Browse Source

feat: add URL formula

Signed-off-by: Mert Ersoy <mertmit99@gmail.com>
pull/1326/head
mertmit 3 years ago committed by Mert Ersoy
parent
commit
2cdd6b97a1
  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> </template>
<span class=" font-weight-bold">{{ column.formula.error.join(', ') }}</span> <span class=" font-weight-bold">{{ column.formula.error.join(', ') }}</span>
</v-tooltip> </v-tooltip>
<div v-else-if="urls" v-html="urls"></div>
<div v-else> <div v-else>
{{ row[column._cn] }} {{ row[column._cn] }}
</div> </div>
@ -17,7 +18,23 @@
<script> <script>
export default { export default {
name: 'FormulaCell', 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> </script>

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

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

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

@ -64,6 +64,32 @@ export default function formulaQueryBuilder(
} }
} }
break; 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: default:
{ {
const res = mapFunctionName({ const res = mapFunctionName({

Loading…
Cancel
Save