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

Add i18n support to app/myelectric in emoncms 9.x #11

Open
wants to merge 15 commits into
base: 9.0
Choose a base branch
from

Conversation

euqip
Copy link

@euqip euqip commented Jan 29, 2016

The support is only possible when enabling user language instead of 'en' with apikey login! This is to be done in user_model.php and is not part of this pull request.

euqip added 7 commits January 29, 2016 17:14
These modifications will only work if the user_model.php file is changed to enable the user language selection with apikey  login.

myelectricmenu.php:
adapted to i18n, install a fr_FR messages file

Myelectric.html:
Réorganised the seperation between code and presentation, to move css outside of page as much as possible.
Install a JS mechanism to translate the hard coded presentation text, myelectric.html page.
create a json dictionnary for translations, ref, en, and fr

myelectric.js
has been partially jslinted

added a README.md file with installation and startup instructions
rem : there is a typo in user_model.php, sql string use language instead of lang
@euqip
Copy link
Author

euqip commented Feb 6, 2016

I think it's now complete.
PS: when using APIKEY to display data is like login in and it gives access to all kind of data the user has access to. Is it not possible to make some restrictions?

@glynhudson
Copy link
Member

Thanks for this, just tested quickly I get error when I try and load emoncms after switching to your branch:

Fatal error: Call to a member function fetch_array() on boolean in /var/www/emoncms/Modules/user/user_model.php on line 443

https://github.com/emoncms/emoncms/blob/master/Modules/user/user_model.php#L443

@euqip
Copy link
Author

euqip commented Feb 7, 2016

Hi glynhudson,

I think I had the same error before I made the database update. I have written the README just after that episode.
App module uses a specific table to store its settings.

Beside the need to update the database, there maybe a better way to advise the user of a missing table.
I will look for it in a near future.

I see two methods:
1 send a message to advise the usser a database update need.
2 force the database update if table does not exist

Which is the best?

I made also a correction in user_model.php
    public function get_lang($userid)
    {
        $userid = intval($userid);
        $result = $this->mysqli->query("SELECT `language` FROM users WHERE id = '$userid';");
        $row = $result->fetch_object();
        return $row->language;
    }
original sql query:
"SELECT `lang` FROM users WHERE id = '$userid';"

I did not fork versiion 9.x.
and changed 2 lines.

@glynhudson
Copy link
Member

I would say the database would need force update since after updating to these changes I could not even load the emoncms login page, therefore is no way to update the database in the usual way. What do you think @TrystanLea ?

@euqip
Copy link
Author

euqip commented Feb 9, 2016

@glynhudson
Please before testing this code, correct the user_model.php file (around line 442) where the sql query selecting user language is incorrect. This error correction is not part of app module.

I added a table existence test and an error page with a direct access to 'admin/db' for a db update using built-in procedure.

@TrystanLea
Copy link
Member

Hello Euqip

I've made the correction to user_model.

I think your check table function needs to be:

public function checktable(){
    // redirect to /admin/db when table does not exist
    $sql = 'SHOW TABLES LIKE "app_config"';
    $result = $this->mysqli->query($sql);
    if ($result->num_rows>0) return true;
    return false;
}

Would you be able to set the colours for the myelectric totals all to blue? as the other colours are more in relation to solarpv etc.

In myelectric config I see the error: "Missing keys in i18n file" should that be shown at this point? could it be hidden if not needed?

@TrystanLea
Copy link
Member

The graph part of my heatpump view has also lost the way the background colour used to stretch to the screen width and are the value colours for solarpv and wind in my energy changed?

@TrystanLea
Copy link
Member

When you adjust the myelectric page width its also doing some strange things.. the realtime graph expands down the page. Is there a way to maintain the previous behaviour? I havent had a chance yet to look through the code in detail

@euqip
Copy link
Author

euqip commented Feb 12, 2016

Hi Tristan and Glyn

In new pullrequest I changed the checktable code the way proposed, its shorter and efficient.
I changed the myelectric colours to blue
I added the missing canvas css rules to keep graph height and width adapted to screen width, without changing height.
In Myheatpump, I checked the original version where the canvas width is fixed to 1200px, and I have kept this width.
You recently added a README and a picture file, mine is maybe toot much.
I removed the missing keys visibility, this was the way I used to collect the texts to translate and may be reused later if any changes occur.
I normally did not change any logic.
I found that in myenergy, when the required feeds does not exist and you save the configuration, the interface hangs. This error is not yet corrected.
When linting the app.js code, I added a bug. it is now restored (the config save did not occur) The original JS code included global variables, undefined variables and vars defined within loops.

Hope it will be better now.

@euqip euqip closed this Feb 12, 2016
@euqip euqip reopened this Feb 12, 2016
@glynhudson
Copy link
Member

Just tested and I'm afraid it still seems to be buggy, see attached for before and after testing your changes screengrabs:

Before:

screenshot 2016-02-13 at 11 54 35 - display 2

After:

screenshot 2016-02-13 at 11 52 10 - display 2

Daily values are incorrectly calculated

Before:

screenshot 2016-02-13 at 11 54 45 - display 2

After:

screenshot 2016-02-13 at 11 52 44 - display 2

Formatting errors

@euqip
Copy link
Author

euqip commented Feb 13, 2016

Hi Glyn,

I have seen your comments on the difference between before and after.

The displayed values are feeds, so I do not understand that the mods I have done will change the results. The feeds are provided by the core application and displayed on screen at a specific place with the desired colour. I am not sure the difference is in code, but in settings.
Could you please provide the content of both app_config data (before and after), or check if they are the same.

For the second view, in mysolarpv, the error is not a formating error, this result is obtained when app.js does not find the required feeds, I had the same with app_config defined like this: "mysolarpv":{"solarpower":[0],"housepower":[0]} remove this content and the formating will be correct.
I tested it in current version and same settings, and got the same result. It's a bug that need a correction, but it's not part of my PR.
To reproduce it, open mysolarpv, open the settings and save with both fields filled with false.

I will check this bug for a correction after the changes I made are acceptable.

@TrystanLea
Copy link
Member

The solar pv page gives the following error in my browser:

TypeError: Math.parseInt is not a function

I think it should be just parseInt (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/parseInt)

Otherwise the myelectric page is now responding correctly to screen resizes :) Although not sure if currency is working properly? it prints pound to screen rather than £, the original works as expected for me.

@TrystanLea
Copy link
Member

++ sorry I see that the heatpump page formatting is actually incorrect in the original too. Im working on a new interface for this so might be best for me to remove this page completely

@euqip
Copy link
Author

euqip commented Feb 13, 2016

Hi Tristan
Because I introduced € (utf-8), the way the page was filled does not work the same way.

this code has been changed

            $("#myelectric_usetoday_units_a").html("&"+app_myelectric.currency+";");
to
            $("#myelectric_usetoday_units_a").html(app_myelectric.currency);

Could you please enter the pound symbol (£) in your settings, and see what happens.
Before, you had £ displayed as a £

Hope it will work better.

I just discovered the € works too. (why not), but if you choose for USD, it will not be ok.
An other way to solve it is to set £ or € in settings to keep all freedom.

@euqip
Copy link
Author

euqip commented Feb 13, 2016

@TrystanLea

parseInt is gives an error in jslint, but works perfect. After having rechecked at W3S and Mozilla, its practically the only math function not using this prefix. I changed my source.

protect solarPV against lock with missing feeds
fallback to 'en' if language js file is missing
insert new texts in i18n js files
further translations possibiilities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants