Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PS-558_tag-selection #362

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
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
12 changes: 12 additions & 0 deletions databox/api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###

###> symfony/webpack-encore-bundle ###
/node_modules/
/public/build/
npm-debug.log
yarn-error.log
###< symfony/webpack-encore-bundle ###
17 changes: 17 additions & 0 deletions databox/api/assets/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Welcome to your app's main JavaScript file!
*
* We recommend including the built version of this JavaScript file
* (and its CSS file) in your base layout (base.html.twig).
*/
// any CSS you import will output into a single css file (admin.css in this case)
import './styles/admin.css';

// start the Stimulus application
import './bootstrap';

import './controllers/initialValuesSource_controller'
import './controllers/initialValuesAdvanced_controller'
import './controllers/initialValuesAll_controller'


12 changes: 12 additions & 0 deletions databox/api/assets/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Welcome to your app's main JavaScript file!
*
* We recommend including the built version of this JavaScript file
* (and its CSS file) in your base layout (base.html.twig).
*/

// any CSS you import will output into a single css file (app.css in this case)
import './styles/app.css';

// start the Stimulus application
import './bootstrap';
11 changes: 11 additions & 0 deletions databox/api/assets/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { startStimulusApp } from '@symfony/stimulus-bridge';

// Registers Stimulus controllers from controllers.json and in the controllers/ directory
export const app = startStimulusApp(require.context(
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
true,
/\.[jt]sx?$/
));

// register any custom, 3rd party controllers here
// app.register('some_controller_name', SomeImportedController);
4 changes: 4 additions & 0 deletions databox/api/assets/controllers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"controllers": [],
"entrypoints": []
}
26 changes: 26 additions & 0 deletions databox/api/assets/controllers/initialValuesAdvanced_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Controller } from '@hotwired/stimulus';
import $ from 'jquery'

export default class extends Controller {
static targets = ['input'];

initialize() {
}

connect() {
this.render();
}

render(event) {
console.log("initialValuesAdvanced::render");

const advanced = event && event.target.checked;
if(advanced) {
$('.initialValuesAll').show(); //.prop('disabled', false);
}
else {
$('.initialValuesAll').hide(); //.prop('disabled', true);
$('.initialValuesSource input').val('');
}
}
}
33 changes: 33 additions & 0 deletions databox/api/assets/controllers/initialValuesAll_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Controller } from '@hotwired/stimulus';
import $ from 'jquery'

export default class extends Controller {
static targets = ['input'];


initialize(e) {
}

connect(e) {
}

tagChanged(js) {
this.inputTarget.value = js;
}

render() {
let tagName = '';
try {
const js = JSON.parse(this.inputTarget.value);
if (js.type === 'metadata') {
tagName = js.value;
}
}
catch (e) {
// bad json, ignore
}

const otherController = this.application.getControllerForElementAndIdentifier($('.initialValuesSource')[0], 'initialValuesSource');
otherController.jsTagChanged(tagName);
}
}
66 changes: 66 additions & 0 deletions databox/api/assets/controllers/initialValuesSource_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Controller } from '@hotwired/stimulus';
import $ from 'jquery'
import TomSelect from "tom-select"

export default class extends Controller {
static targets = ['input'];


initialize(e) {
}

connect(e) {
}
jygaulier marked this conversation as resolved.
Show resolved Hide resolved

render(event) {
const tagName = event.target.tomselect.getValue();
let js = '';
if(tagName !== '') {
js = JSON.stringify(
{
'type': 'metadata',
'value': tagName
},
null,
2
);
}

const otherController = this.application.getControllerForElementAndIdentifier($('.initialValuesAll')[0], 'initialValuesAll');
otherController.tagChanged(js);

// this.dispatch('tagChanged', {detail: js});
}

jsTagChanged(tagName) {
const tom = $('.initialValuesSource SELECT')[0].tomselect;
let handler;

// load("") would load 100 first elements, we don't want that
if(tagName) {
// ??? buggy if we declare the callback immediatly (tagName value is one step "old")
// solution is to _generate_ the callback, injecting the current tagName value ???
const gethandler = function(tn) {
return function (data) {
this.off('load', handler)
if (data && data[0].entityId === tn) {
this.setValue(data[0].entityId, true);
}
else {
this.setValue('', true); // silent=true: do NOT generate "changed" event (else it will clear the js)
}
};
};
// we can update the select value only after load is finished
handler = gethandler(tagName);
tom.on('load', handler);
tom.load(tagName);
// tom will NOT call the handler if no need to fetch data (cache ?) so we enforce setValue here in case of...
tom.setValue(tagName, true);
}
else {
tom.setValue('', true);
}
}

}
17 changes: 17 additions & 0 deletions databox/api/assets/styles/admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.form-group.helpAtRight .form-control {
width:50%;
float: left;
}
.form-group.helpAtRight .form-help {
padding-left:10px;
display: block;
width: 50%;
float: right;
}
.form-group.helpAtRight .form-help .label {
font-size: x-small;
font-weight: bold;
}
.form-group.helpAtRight .form-help CODE {
font-size: x-small;
}
Empty file.
1 change: 1 addition & 0 deletions databox/api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"symfony/serializer": "^5.2.0",
"symfony/twig-bundle": "^5.2.0",
"symfony/validator": "^5.2.0",
"symfony/webpack-encore-bundle": "^2.0",
"symfony/yaml": "^5.2.0"
},
"require-dev": {
Expand Down
Loading