howardjones / network-weathermap

Network Weathermap draws diagrams from data
http://www.network-weathermap.com/
MIT License
426 stars 94 forks source link

Editor on Cacti not working (PHP Weathermap version 1.0.0dev) #126

Closed pautiina closed 6 years ago

pautiina commented 6 years ago

Hello. Editor not work correctly. When I open editor, browser console have next error:

ncaught SyntaxError: Unexpected token <
jquery.min.js:2 jQuery.Deferred exception: fromplug is not defined ReferenceError: fromplug is not defined
    at attach_click_events (http://noc/cacti/plugins/weathermap/editor-resources/editor.js:83:5)
    at HTMLDocument.initJS (http://noc/cacti/plugins/weathermap/editor-resources/editor.js:59:9)
    at j (http://noc/cacti/plugins/weathermap/vendor/jquery/dist/jquery.min.js:2:29999)
    at k (http://noc/cacti/plugins/weathermap/vendor/jquery/dist/jquery.min.js:2:30313) undefined
r.Deferred.exceptionHook @ jquery.min.js:2
jquery.min.js:2 jQuery.Deferred exception: imlist is not defined ReferenceError: imlist is not defined
    at HTMLDocument.initJS16 (http://noc/cacti/plugins/weathermap/editor-resources/editor16.js:13:17)
    at j (http://noc/cacti/plugins/weathermap/vendor/jquery/dist/jquery.min.js:2:29999)
    at k (http://noc/cacti/plugins/weathermap/vendor/jquery/dist/jquery.min.js:2:30313) undefined
r.Deferred.exceptionHook @ jquery.min.js:2
jquery.min.js:2 Uncaught ReferenceError: fromplug is not defined
    at attach_click_events (editor.js:83)
    at HTMLDocument.initJS (editor.js:59)
    at j (jquery.min.js:2)
    at k (jquery.min.js:2)
jquery.min.js:2 Uncaught ReferenceError: imlist is not defined
    at HTMLDocument.initJS16 (editor16.js:13)
    at j (jquery.min.js:2)
    at k (jquery.min.js:2)

and on cacti log:

2018/01/31 10:02:35 - CMDPHP PHP ERROR NOTICE Backtrace: (/plugins/weathermap/weathermap-cacti10-plugin-editor.php: 25 require_once)(/plugins/weathermap/editor.php: 34 main)(/plugins/weathermap/lib/Weathermap/Editor/EditorUI.php: 932 showMainPage)(/plugins/weathermap/lib/Weathermap/Editor/EditorUI.php: 1123 fetch)(/plugins/weathermap/lib/Weathermap/UI/SimpleTemplate.php: 48 include)(/plugins/weathermap/editor-resources/templates/main-oldstyle.php: 28 CactiErrorHandler)(/lib/functions.php: 4516 cacti_debug_backtrace)
--
2018/01/31 10:02:35 - ERROR PHP NOTICE in Plugin 'weathermap': Use of undefined constant host_url - assumed 'host_url' in file: /var/www/data/cacti/plugins/weathermap/editor-resources/templates/main-oldstyle.php on line: 28
dabeani commented 6 years ago

same problem here!

netniV commented 6 years ago

The second can be fixed by editing editor-resources/templates/main-oldstyle.php at line 28 and changing it to:

var host_url = <?php echo $host_url ?>;

However, do note that $host_url or the $tpl->set("host_url"); isn't actually primed with the correct URL yet (or I've missed how it was set).

howardjones commented 6 years ago

I was testing this last night after @pautiina mentioned it in the forum, and didn't see any error, using the editor directly (I use php -S 0.0.0.0:8000 to test). Very odd. Thanks for the correction. The 'return url' is quite likely not passed all the way through. I'll look at that today.

netniV commented 6 years ago

That's strange given it's a 'constant' conversion warning. Maybe the error_reporting() isn't set properly if running that way to include warnings or notices?

netniV commented 6 years ago

Maybe try with debuging with:

php -S 0.0.0.0:8000 -d error_reporting=22527 -d display_errors=1

The number is the number that error_reporting would return after you set the appropriate levels. The above should be E_ALL & ~E_DEPRECATED

This would override any settings in php.ini for the cli or apache. It wouldn't override if a script changes it.

howardjones commented 6 years ago

Agreed (re: error reporting).

Also, a bug in your fix ;-) The value for host_url is a string, so the actual change is:

    var host_url = '<?php echo $host_url ?>';

(with the quotes)

Just testing a slightly wider patch that actually sets the value though ;-)

howardjones commented 6 years ago

ncaught SyntaxError: Unexpected token <

I can't figure out where this is coming from though.

pautiina commented 6 years ago

I have update code. Now when on browser open link cacti/plugins/weathermap/weathermap-cacti10-plugin-editor.php for choose map for edit on browser console have next warning and error:

jquery.min.js:2 jQuery.Deferred exception: imlist is not defined ReferenceError: imlist is not defined
    at HTMLDocument.initJS16 (http://noc/cacti/plugins/weathermap/editor-resources/editor16.js:13:17)
    at j (http://noc/cacti/plugins/weathermap/vendor/jquery/dist/jquery.min.js:2:29999)
    at k (http://noc/cacti/plugins/weathermap/vendor/jquery/dist/jquery.min.js:2:30313) undefined
r.Deferred.exceptionHook @ jquery.min.js:2
k @ jquery.min.js:2
setTimeout (async)
(anonymous) @ jquery.min.js:2
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
fire @ jquery.min.js:2
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
S @ jquery.min.js:3
jquery.min.js:2 Uncaught ReferenceError: imlist is not defined
    at HTMLDocument.initJS16 (editor16.js:13)
    at j (jquery.min.js:2)
    at k (jquery.min.js:2)
initJS16 @ editor16.js:13
j @ jquery.min.js:2
k @ jquery.min.js:2
setTimeout (async)
r.readyException @ jquery.min.js:2
(anonymous) @ jquery.min.js:2
j @ jquery.min.js:2
k @ jquery.min.js:2
setTimeout (async)
(anonymous) @ jquery.min.js:2
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
fire @ jquery.min.js:2
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
k @ jquery.min.js:2
setTimeout (async)
(anonymous) @ jquery.min.js:2
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
fire @ jquery.min.js:2
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
S @ jquery.min.js:3
favicon.ico:1 GET http://noc/favicon.ico 404 (Not Found)

but editor workly and I can edit map. The screenshot shows more clearly: image

pautiina commented 6 years ago

And new error when I try change map properties;

editor.js:136 Uncaught TypeError: Cannot read property 'slice' of undefined
    at HTMLInputElement.help_handler (editor.js:136)
    at HTMLInputElement.dispatch (jquery.min.js:3)
    at HTMLInputElement.q.handle (jquery.min.js:3)
help_handler @ editor.js:136
dispatch @ jquery.min.js:3
q.handle @ jquery.min.js:3

image

netniV commented 6 years ago

imlist comes from EditorUI.php:

$imagesJSON = "\nvar imlist = " . json_encode($imageList) . ";\n";
$tpl->set("images_json", $imagesJSON);

editor-resources/template/main-oldstyle.php and main.php output $images_json:

    <script type="text/javascript">
        <?php echo $map_json; ?>
        <?php echo $images_json; ?>
        <?php echo $fonts_json; ?>
        <?php echo $editor_settings; ?>

        var $global_settings = <?php echo $global; ?>;
        var $global_settings2 = <?php echo $global2; ?>;
        var editor_url = '<?php echo $editor_name; ?>';
        var fromplug = <?php echo $fromplug ?>;
        var host_url = <?php echo host_url ?>;
    </script>

The editor-resources/editor16.js should probably check whether imlist is null before looping through it though:

function initJS16() {

    jQuery.each(imlist, function (index, value) {
        // slot in the list of images in:
        //    node icon selectbox
        //    map background image
        var newitem = jQuery("<option />").attr("value", value).text(value);
        jQuery(".imlist").append(newitem);
    });

    jQuery.each(fontlist, function (index, value) {
        // slot in the list of fonts in each of the select boxes where they are expected
        var newitem = jQuery("<option />").attr("value", value).text(value);
        jQuery(".fontlist").append(newitem);
    });

Should become:

function initJS16() {   

    if (imlist != null) 
    jQuery.each(imlist, function (index, value) {
        // slot in the list of images in:
        //    node icon selectbox
        //    map background image
        var newitem = jQuery("<option />").attr("value", value).text(value);
        jQuery(".imlist").append(newitem);
    });

    if (fontlist != null)
    jQuery.each(fontlist, function (index, value) {
        // slot in the list of fonts in each of the select boxes where they are expected
        var newitem = jQuery("<option />").attr("value", value).text(value);
        jQuery(".fontlist").append(newitem);
    });

Though @howardjones may find that this is a problem elsewhere since they shouldn't actually be null. You could add a debugger; statement as the first line of initJS16() to check that

howardjones commented 6 years ago

No, it should check. Or it shouldn't be included on the front-oldstyle.php template. That's where this error shows up (for me anyway), because in the front page, the same variable dump doesn't happen, so they are null. The better way is probably to break out any javascript used on the front picker page into another file. I don't think there is much - just the thing that hides the warning that javascript isn't enabled.

netniV commented 6 years ago

One other thing I noticed from above, it's not just host_url that should be quoted... shouldn't the others too? $global, $global2 and $editor_settings? (unless these are already defined as being arrays or quoted)

howardjones commented 6 years ago

No, they are created from json_encode() so they are already valid javascript objects.

netniV commented 6 years ago

I did wonder why they hadn't flagged up yet šŸ‘

dabeani commented 6 years ago

thx so far, its working now for me :+1:

pautiina commented 6 years ago

Now these errors are not present. But the editor is still not working properly. The editor does not read the map parameters from the configuration file, nor does it change them. image

pautiina commented 6 years ago

I also can not edit thith parametr for editor: image

pautiina commented 6 years ago

Not display button for choose data sourse , info_url graph and overlib graph image

howardjones commented 6 years ago

No-one ever said the editor was working completely - it's been rewritten completely (apart from the javascript) since 0.98. The basic editing for nodes and links works, but quite a few things around the edges don't.

The picker link should show up though. I'll check that again. (although I already know you'll get a HTTP 500 error when the picker opens)

pautiina commented 6 years ago

When I open on browser url editor.php I have button for [Pick from Cacti] but when I click for this link I have error, but not HTTP 500: image

netniV commented 6 years ago

No-one ever said the editor was working completely - it's been rewritten completely (apart from the javascript) since 0.98. The basic editing for nodes and links works, but quite a few things around the edges don't.

The editor isn't fully functionality šŸ˜± šŸ¤£

howardjones commented 6 years ago

Well, yeah, but even more than before :-) But it's a lot easier to read than it used to be.

pautiina commented 6 years ago

Ok, now I have link for choose data source and it's work.

But I have many device name on Cyrillic (russian) my database have utf8mb4 collection and it's dafault charset for cacti:

image

dabeani commented 6 years ago

for me (austria) it works! thanks! perfect work, and thank you very much for your work on that. But, if i want to create links between Nodes, i get following error: weathermap-cacti10-plugin-mgmt.php // editor.js:84 Uncaught ReferenceError: NodeIDs is not defined at HTMLAreaElement.click_handler (editor.js:213) at HTMLAreaElement.dispatch (jquery.min.js:2) at HTMLAreaElement.y.handle (jquery.min.js:2)

netniV commented 6 years ago

@howardjones You're getting things closer so people's expectations are raising ;-)

howardjones commented 6 years ago

@dabeani That sounds like you might have an old version of editor-resources/editor.js... Will confirm though.

howardjones commented 6 years ago

Not sure why commit comments aren't appearing in the issue any more... Anyway, you can add links now @dabeani And @pautiina can look at (but not update) map properties. Still some work to do there. Will have to figure out the utf8 stuff - I haven't done anything special there.

netniV commented 6 years ago

I tend to make sure to add # and the issue number somewhere just so it shows up

howardjones commented 6 years ago

Forgot to push. D'oh. That wasn't it last time though.

howardjones commented 6 years ago

@pautiina I am able to see Cyrillic hostnames in the picker now with 5c3d53b

pautiina commented 6 years ago

@howardjones Many thanks. Really. Now normally displayed.

pautiina commented 6 years ago

Hello. I have retest the latest code. Visual editor work normally. But when I choose device for data source my browser print some php notice:

Notice: Undefined index: target in /var/www/data/cacti/plugins/weathermap/lib/Weathermap/Integrations/Cacti/EditorDataPicker.php on line 147

image

netniV commented 6 years ago

I think there is a change that @howardjones is working on. If I recall over the weekend I saw that he had not pushed it out yet because it relied on another change. This may be related (or not šŸ¤·ā€ā™‚ļø )

howardjones commented 6 years ago

No, this is a bug. I'll take a look later today.

howardjones commented 6 years ago

Closing this now. As far as I know, the editor is back to the functionality of 0.98 again.