You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by ahgittin <gi...@git.apache.org> on 2018/11/22 11:09:33 UTC
[GitHub] brooklyn-ui pull request #113: Fix template overrides - decorate `script` di...
GitHub user ahgittin opened a pull request:
https://github.com/apache/brooklyn-ui/pull/113
Fix template overrides - decorate `script` directive to prevent re-overriding of templates
by default `<script>` will install to template cache whenever it is processed as a directive.
this decorates it to be no-op if there is already something in the cache with that name,
allowing programmatic overrides of templates configured using `<script id="...">` notation.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ahgittin/brooklyn-ui fix-template-overrides
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/brooklyn-ui/pull/113.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #113
----
commit 722d2515edb9ed7c6322191cf5477d19d2b27f0a
Author: Alex Heneveld <al...@...>
Date: 2018-11-22T11:07:20Z
install template to cache earlier
not really needed, but is consistent with how done elsewhere,
and allows override
commit b04423b169e0d9a749ace79ccd446b4c6f3bb232
Author: Alex Heneveld <al...@...>
Date: 2018-11-22T11:07:47Z
decorate `script` directive to prevent re-overriding of templates
by default `<script>` will install to template cache whenever it is processed as a directive.
this decorates it to be no-op if there is already something in the cache with that name,
allowing programmatic overrides of templates configured using `<script id="...">` notation.
----
---
[GitHub] brooklyn-ui pull request #113: Fix template overrides - decorate `script` di...
Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/113#discussion_r235922436
--- Diff: ui-modules/utils/script-tag-non-overwrite/script-tag-non-overwrite.js ---
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import angular from 'angular';
+
+/**
+ * If included, this decorates the default angular `<script>` tag so that it checks the
+ * template cache and does _not_ put the contents of the `script` into the cache if there
+ * is already an element with that ID present.
+ */
+
+const MODULE_NAME = 'brooklyn.components.script-tag-non-overwrite';
+
+angular.module(MODULE_NAME, [])
+ .decorator('scriptDirective', ['$delegate', '$templateCache', scriptTagDirectiveDecorator]);
+
+export default MODULE_NAME;
+
+const BROOKLYN_CONFIG = 'brooklyn.config';
+
+function scriptTagDirectiveDecorator($delegate, $templateCache) {
+ let base = $delegate[0];
+ return [ Object.assign({}, base, { compile: function(el, attr) {
+ let match = $templateCache.get(attr.id);
+ if (!(match === null || typeof match === 'undefined')) {
--- End diff --
@ahgittin Aye, that was the use-case I had in mind. I don't think it's strictly speaking required but better safe than sorry => I think it would be better to do this change.
Although, there is another solution that is even simpler: don't decorate the `script` directive and update the way we register template to do that in a ` .config` block (like the main template) rather than using `<script>` tags
---
[GitHub] brooklyn-ui pull request #113: Fix template overrides - decorate `script` di...
Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/113#discussion_r235903512
--- Diff: ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js ---
@@ -79,7 +82,7 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani
model: '='
},
controller: ['$scope', '$element', controller],
- template: template,
+ templateUrl: TEMPLATE_URL,
--- End diff --
While do do this, could you change it to match what the other directive do? https://github.com/apache/brooklyn-ui/blob/b04423b169e0d9a749ace79ccd446b4c6f3bb232/ui-modules/blueprint-composer/app/components/dsl-viewer/dsl-viewer.js#L35-L37
So it can be overridden directly from the attribute `template-url` on the directive itself.
---
[GitHub] brooklyn-ui pull request #113: Fix template overrides - decorate `script` di...
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/113#discussion_r235917516
--- Diff: ui-modules/utils/script-tag-non-overwrite/script-tag-non-overwrite.js ---
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import angular from 'angular';
+
+/**
+ * If included, this decorates the default angular `<script>` tag so that it checks the
+ * template cache and does _not_ put the contents of the `script` into the cache if there
+ * is already an element with that ID present.
+ */
+
+const MODULE_NAME = 'brooklyn.components.script-tag-non-overwrite';
+
+angular.module(MODULE_NAME, [])
+ .decorator('scriptDirective', ['$delegate', '$templateCache', scriptTagDirectiveDecorator]);
+
+export default MODULE_NAME;
+
+const BROOKLYN_CONFIG = 'brooklyn.config';
+
+function scriptTagDirectiveDecorator($delegate, $templateCache) {
+ let base = $delegate[0];
+ return [ Object.assign({}, base, { compile: function(el, attr) {
+ let match = $templateCache.get(attr.id);
+ if (!(match === null || typeof match === 'undefined')) {
--- End diff --
i wondered about this too. we have unique names for all our things and i don't see any way someone would have registered a template that isn't meant to override our things, so didn't think we needed an "opt-out".
however there is a risk with 3rd party libraries that templates might have non-unique names and this could cause an issue there. doesn't seem to be a problem but if we're concerned what i'd suggest is that we make this behaviour "opt-in", checking an extra attribute e.g. `defer-to-preexisting-id`, which we set everywhere in our code that we define a `<script id="..." ...` tag.
not sure it's needed but will add if you think so @tbouron .
---
[GitHub] brooklyn-ui pull request #113: Fix template overrides - decorate `script` di...
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/113#discussion_r235925594
--- Diff: ui-modules/utils/script-tag-non-overwrite/script-tag-non-overwrite.js ---
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import angular from 'angular';
+
+/**
+ * If included, this decorates the default angular `<script>` tag so that it checks the
+ * template cache and does _not_ put the contents of the `script` into the cache if there
+ * is already an element with that ID present.
+ */
+
+const MODULE_NAME = 'brooklyn.components.script-tag-non-overwrite';
+
+angular.module(MODULE_NAME, [])
+ .decorator('scriptDirective', ['$delegate', '$templateCache', scriptTagDirectiveDecorator]);
+
+export default MODULE_NAME;
+
+const BROOKLYN_CONFIG = 'brooklyn.config';
+
+function scriptTagDirectiveDecorator($delegate, $templateCache) {
+ let base = $delegate[0];
+ return [ Object.assign({}, base, { compile: function(el, attr) {
+ let match = $templateCache.get(attr.id);
+ if (!(match === null || typeof match === 'undefined')) {
--- End diff --
okay, done @tbouron , see last commit
---
[GitHub] brooklyn-ui pull request #113: Fix template overrides - decorate `script` di...
Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/113#discussion_r235904114
--- Diff: ui-modules/utils/script-tag-non-overwrite/script-tag-non-overwrite.js ---
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import angular from 'angular';
+
+/**
+ * If included, this decorates the default angular `<script>` tag so that it checks the
+ * template cache and does _not_ put the contents of the `script` into the cache if there
+ * is already an element with that ID present.
+ */
+
+const MODULE_NAME = 'brooklyn.components.script-tag-non-overwrite';
+
+angular.module(MODULE_NAME, [])
+ .decorator('scriptDirective', ['$delegate', '$templateCache', scriptTagDirectiveDecorator]);
+
+export default MODULE_NAME;
+
+const BROOKLYN_CONFIG = 'brooklyn.config';
+
+function scriptTagDirectiveDecorator($delegate, $templateCache) {
+ let base = $delegate[0];
+ return [ Object.assign({}, base, { compile: function(el, attr) {
+ let match = $templateCache.get(attr.id);
+ if (!(match === null || typeof match === 'undefined')) {
--- End diff --
I would be reluctant to change the default behaviour for the entire application without a possibility to go back. I think it would be wise to add a `override` (or a better name) parameter to revert to the default behaviour is we need/want to
---
[GitHub] brooklyn-ui issue #113: Fix template overrides - decorate `script` directive...
Posted by sferot <gi...@git.apache.org>.
Github user sferot commented on the issue:
https://github.com/apache/brooklyn-ui/pull/113
It works fine for me :+1:
---
[GitHub] brooklyn-ui pull request #113: Fix template overrides - decorate `script` di...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/brooklyn-ui/pull/113
---
[GitHub] brooklyn-ui pull request #113: Fix template overrides - decorate `script` di...
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/113#discussion_r235916351
--- Diff: ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js ---
@@ -79,7 +82,7 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani
model: '='
},
controller: ['$scope', '$element', controller],
- template: template,
+ templateUrl: TEMPLATE_URL,
--- End diff --
good spot, sorry i missed this!
---