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 all 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 ###
16 changes: 16 additions & 0 deletions databox/api/assets/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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/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": []
}
36 changes: 36 additions & 0 deletions databox/api/assets/controllers/initialValuesAll_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Controller } from '@hotwired/stimulus';
import $ from 'jquery'

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

initialValuesSourceOutletConnected(e) {
// tomselect will only be set AFTER connect (?) so we update the select after return (in fact 1 ms is enough...)
// https://github.com/hotwired/stimulus/issues/618
setTimeout(
() => { this.render(); },
100
);
}

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);
}
}
62 changes: 62 additions & 0 deletions databox/api/assets/controllers/initialValuesSource_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Controller } from '@hotwired/stimulus';
import $ from 'jquery'
import TomSelect from "tom-select"

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

initialize() {
this.handler = null;
this.tagNameToSet = null;
}

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

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

gethandler(tom) {
return (data) => {
if (data && data[0].entityId === tom.tagNameToSet) {
tom.setValue(data[0].entityId, true);
}
else {
tom.setValue('', true); // silent=true: do NOT generate "changed" event (else it will clear the js)
}
};
};

jsTagChanged(tagName) {
const tom = $('.initialValuesSource SELECT')[0].tomselect;
if(!tom) {
return;
}

// load("") would load 100 first elements, we don't want that
if(tagName) {
// we can update the select value only after load is finished
if(!this.handler) {
tom.on('load', this.handler = this.gethandler(tom));
}
tom.load(tom.tagNameToSet = tagName);
// tom will NOT call the handler if no need to fetch data (cache ?) so we enforce setValue just in case.
tom.setValue(tagName, true);
}
else {
tom.setValue('', true);
}
}
}
23 changes: 23 additions & 0 deletions databox/api/assets/styles/admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.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;
white-space: pre-wrap;
}

.initialValuesAll TEXTAREA {
font-family: monospace;
font-size: smaller;
}
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
95 changes: 83 additions & 12 deletions databox/api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions databox/api/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@
Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle::class => ['all' => true],
Alchemy\MetadataManipulatorBundle\AlchemyMetadataManipulatorBundle::class => ['all' => true],
Alchemy\WorkflowBundle\AlchemyWorkflowBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
];
Loading