Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions app/assets/stylesheets/investments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
}

&--cell-heading {
flex: 0 0 20%;
flex: 0 0 25%;
font-size: $f6;
font-weight: 700;
line-height: 19px;
Expand All @@ -254,6 +254,11 @@
line-height: 29px;
}

&--table-container {
margin-top: 1rem;
margin-bottom: 1rem;
}

&--inner-table-row {
display: flex;
align-items: baseline;
Expand All @@ -273,6 +278,41 @@
}
}

&--inner-table-header {
background-color: rgba($color_headers, 0.04);
padding: 0.5rem 0;
border-bottom: 2px solid $separator_dark;
margin-bottom: 0.5rem;

&:not(:first-child) {
margin-top: 0;
}
}

&--inner-table-cell {
flex: 1;
word-break: break-word;

&:not(:first-child) {
padding-left: 1rem;
}

&--date {
flex: 0 0 100px;
min-width: 100px;
}

&--vocabulary {
flex: 0 0 110px;
min-width: 110px;
}

&--text {
flex: 2;
min-width: 300px;
}
}

&--icon-text {
display: flex;
align-items: baseline;
Expand Down Expand Up @@ -307,16 +347,16 @@
> * {
padding: 1em 0;
border-bottom: 1px solid $separator_dark;
}

&:first-of-type {
padding-top: 0;
.gobierto-filter--hide-dropdown {
padding-top: 0;

.gobierto-vue-dropdown--trigger {
display: none;
.gobierto-vue-dropdown--trigger {
display: none;

& + * {
margin-top: 0;
}
& + * {
margin-top: 0;
}
}
}
Expand Down Expand Up @@ -606,7 +646,7 @@
}
}

$ranges-opacity: 10%, 25%, 40%, 60%, 75%, 90%, 100%;
$ranges-opacity: 13%, 25%, 38%, 50%, 63%, 75%, 88%, 100%;

&--item {
flex: 0 0 calc(100% / #{length($ranges-opacity)});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def load_vocabulary
end

def term_params
params.require(:term).permit(name_translations: {})
params.require(:term).permit(:external_id, name_translations: {})
end

def set_admin_by_session_or_token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@
</div>

<!-- Table type -->
<div v-if="type === 'table'">

<div
v-if="type === 'table' && table && table.columns"
class="investments-project-main--table-container"
>
<!-- Table header with column titles -->
<div class="investments-project-main--inner-table-row investments-project-main--inner-table-header">
<div
v-for="column in table.columns"
:key="`header-${column.id}`"
:class="getCellClass(column)"
>
<strong>{{ translate(column.name_translations) }}</strong>
</div>
</div>
<!-- Table rows with data -->
<div
v-for="(v, i) in value"
:key="`${v}-${i}`"
Expand All @@ -14,19 +29,26 @@
<div
v-for="column in table.columns"
:key="`${column.id}-${v}`"
:class="getCellClass(column)"
>
<div v-if="column.filter === 'money'">
{{ v[column.id] | money }}
<div v-if="column.type === 'vocabulary'">
{{ getVocabularyValue(column.id, v[column.id]) }}
</div>
<div v-else-if="column.filter === 'date'">
<div v-else-if="column.type === 'date' || column.filter === 'date'">
{{ v[column.id] | date }}
</div>
<div v-else-if="column.type === 'money' || column.filter === 'money'">
{{ v[column.id] | money }}
</div>
<div v-else>
{{ v[column.id] }}
</div>
</div>
</div>
</div>
<div v-else-if="type === 'table' && (!table || !table.columns)">
<em>{{ value || "Table configuration missing" }}</em>
</div>

<!-- Icon type -->
<div v-else-if="type === 'icon'">
Expand Down Expand Up @@ -90,6 +112,51 @@ export default {
type: Object,
default: () => {}
}
},
data() {
return {
vocabularyLookup: {}
};
},
created() {
if (this.type === 'table' && this.table && this.table.vocabulary_terms) {
this.buildVocabularyLookup();
}
},
methods: {
buildVocabularyLookup() {
// Build a lookup dictionary from vocabulary_terms
// vocabulary_terms contains all terms for all vocabularies used in the table
if (Array.isArray(this.table.vocabulary_terms)) {
this.table.vocabulary_terms.forEach(term => {
// Map term id to translated name
this.vocabularyLookup[term.id] = this.translate(term.name_translations);
});
}
},
getVocabularyValue(columnId, value) {
// Look up the term by its ID
if (this.vocabularyLookup[value]) {
return this.vocabularyLookup[value];
}
// Fallback to original value if not found
return value || '-';
},
getCellClass(column) {
const baseClass = 'investments-project-main--inner-table-cell';
const type = column.type || column.filter || 'text';

// Map column types to CSS classes
const typeClasses = {
'date': `${baseClass} ${baseClass}--date`,
'vocabulary': `${baseClass} ${baseClass}--vocabulary`,
'money': `${baseClass} ${baseClass}--vocabulary`,
'text': `${baseClass} ${baseClass}--text`
};

// Return specific class or default to vocabulary width
return typeClasses[type] || `${baseClass} ${baseClass}--vocabulary`;
}
}
};
</script>
31 changes: 20 additions & 11 deletions app/javascript/gobierto_investments/webapp/conf/mataro.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ export default {
maxZoom: 16
},
availableFilters: [
{
id: "date",
startKey: "data-inici",
endKey: "data-final",
},
{
id: "estat"
},
{
id: "any-estat"
id: "any-pla-inversions"//,
// allowedValues: ["2024", "2025"]
},
{
id: "tipus"
Expand All @@ -33,7 +29,10 @@ export default {
id: "tipus-projecte"
},
{
id: "import"
id: "zones"
},
{
id: "consells-territorials"
}
],
displayGalleryFieldTags: false,
Expand Down Expand Up @@ -76,6 +75,9 @@ export default {
{
type: "separator"
},
{
id: "data-inici-obra"
},
{
id: "data-inici-redaccio"
},
Expand All @@ -91,20 +93,27 @@ export default {
{
id: "data-final"
},
{
id: "data-final-obra"
},
{
type: "separator"
},
{
id: "import"
id: "import-adjudicacio-ambiva"
},
{
id: "import-adjudicacio"
id: "import-licitacio-ambiva"
},
{
id: "import-liquidacio"
id: "import-liquidacio-ambiva"
},
{
type: "separator"
},
{
id: "partida"
id: "estats",
type: "table"
}
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:count="phase.count"
:budget="phase.budget | money"
:projects="phase.items"
:is-negative="i > 2"
:is-negative="i > 3"
/>
</div>
</template>
Expand Down
15 changes: 14 additions & 1 deletion app/javascript/gobierto_investments/webapp/mixins/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,24 @@ export const CommonsMixin = {
attr.field_type = "money"
}

// Extract table configuration from plugin_configuration if type is table
let table = element.table;
if (element.type === "table" && attr.options?.configuration?.plugin_configuration) {
table = attr.options.configuration.plugin_configuration;

// Add vocabulary_terms from metadata to table configuration
// The metadata provides vocabulary_terms for all vocabularies in vocabulary_ids
if (table && attr.vocabulary_terms) {
table.vocabulary_terms = attr.vocabulary_terms;
}
}

return {
...attr,
...element,
name: this.translate(attr.name_translations),
value: value
value: value,
table: table
};
},
setItem(element, metadata) {
Expand Down
6 changes: 3 additions & 3 deletions app/javascript/lib/i18n/modules/translations.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions app/javascript/lib/shared/modules/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Middleware {
const filters = [];

for (let index = 0; index < this.filters.length; index++) {
const { id: key, ...rest } = this.filters[index];
const { id: key, allowedValues, hideDropdown, ...rest } = this.filters[index];
const element = stats[key];
const { field_type: type, vocabulary_terms: options = [], name_translations: title = {} } = this.getAttributesByKey(key);

Expand All @@ -20,7 +20,9 @@ export class Middleware {
title: translate(title),
options: Array.isArray(options) ? options.map(opt => ({ ...opt, title: translate(opt.name_translations) })) : [],
type: type ? type : key,
key
key,
allowedValues,
hideDropdown
});
}

Expand Down
23 changes: 9 additions & 14 deletions app/javascript/lib/vue/components/modules/Filters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
>{{ labelClear }}</span>
</transition>

<template v-for="filter in filters">
<div
v-for="filter in filters"
:key="filter.key"
:class="{ 'gobierto-filter--hide-dropdown': filter.hideDropdown }"
>
<!-- Filter type: calendar -->
<template v-if="filter.type === 'date'">
<Dropdown
:key="filter.key"
@is-content-visible="filter.rotate = !filter.rotate"
>
<Dropdown @is-content-visible="filter.rotate = !filter.rotate">
<template #trigger>
<BlockHeader
:rotate="filter.rotate"
Expand All @@ -34,10 +35,7 @@

<!-- Filter type: checkbox -->
<template v-else-if="filter.type === 'vocabulary_options'">
<Dropdown
:key="filter.key"
@is-content-visible="filter.rotate = !filter.rotate"
>
<Dropdown @is-content-visible="filter.rotate = !filter.rotate">
<template #trigger>
<BlockHeader
:rotate="filter.rotate"
Expand All @@ -63,10 +61,7 @@

<!-- Filter type: numeric range -->
<template v-else-if="filter.type === 'numeric'">
<Dropdown
:key="filter.key"
@is-content-visible="filter.rotate = !filter.rotate"
>
<Dropdown @is-content-visible="filter.rotate = !filter.rotate">
<template #trigger>
<BlockHeader
:rotate="filter.rotate"
Expand All @@ -89,7 +84,7 @@
/>
</Dropdown>
</template>
</template>
</div>
</div>
</template>

Expand Down
Loading