Sunday 31 May 2020

TimeStamp interesting

I had trouble in saving date into database and read it again.

received date: DateTime
collected date: TimeZone








In summary

  • I created all columns as TimeZone.
  • When read in js side, just do substring(0,10) to remove 10:00 hour time..
  • Show in chrome date type.
  • When saving, rely on whatever API does, and let it save with 10:00 hour time.


MySQL check current time zone (https://stackoverflow.com/questions/2934258/how-do-i-get-the-current-time-zone-of-mysql) shows below. And it seems my MYSQL follows my local machine time stamp - AEST.



So far so good.
The problem happens when reading the date value again in to javascript.





When reading the database value '2020-06-01 10:00 AEST' into API and into js, in some how, it becomes '2020-06-01 00:00 AEST'.

This leads js display incorrect giving 31/5 not 1/6.



The resolutions is, whatever date you have in javascript, you ignore the timezone, and just convert the value (2020-06-01 00:00 AEST) into string.



Javascript fun fact

Datetime is funny in java script. new Date(null) is 1970-1-1.







Friday 29 May 2020

Lumen - insert datetime

At one stage, I couldn't insert a record into table with datetime format.
I know MySQL supports DateTime and TimeStamp for date formats. I tried both of them, error still was same.




Error message was below.

Invalid datetime format: 1292 Incorrect datetime value: '2020-05-29T12:09:52.000Z' for column 'dt_date_received'.

I knew that it was API error. js gave current time as 'new Date()'. And API received it as string. And it had timezone information from the js date (you cannot remove this timezone information because js date is just integer value basically in some way).

Imagine you run SQL command below. You will get exactly the same error as above.



I couldn't figure out, so I tried API Test, which I made for simple CRUD test. It didn't work here either. In below, the first two 'ggg' was inserted into store, but not database. So it didn't show id.



Then I googled how to edit $request data in Laravel. And I found below link!
https://stackoverflow.com/questions/36812476/how-to-change-value-of-a-request-parameter-in-laravel



You can edit the $request data before inserting into database.


The data was inserted as expected!
Further, I replaced the given dt_date_received with replacing 'T' and 'Z'.




It was working.

Actually all this errors happened because I had to include 'dt_date_received' into 'fillable' to update/create record with that column information.



You need this to create record with some timestamp value.


Imagine you omit the line 25 in the above picture. Then it becomes you try below SQL query.


And in this case, because 'dt_date_received' is 'not null' column, you will have another error.
'dt_date'_received' cannot be null.


In Summary,

  1. If insert is not working, go for API Test for simple testing
  2. Read error message
  3. Try API code change to resolve the issue.


Sunday 10 May 2020

EmberTable Debugging

At one stage, ember table showed nothing. Page frozen.

Columns was defined.
this.columns = [
  {
    name: `ID`,    valuePath: `id`  },  {
    name: `Name`,    valuePath: `full_name`  },  {
    name: `VIP`,    valuePath: `vip`  },  {
    name: `Problem`,    valuePath: `problem`  },  {
    name: `Received Date`,    valuePath: `dt_date_received`  },  {
    name: `Quoted Date`,    valuePath: `dt_date_quoted`  },  {
    name: `Prom. Completion Date`,    valuePath: `dt_date_completion`  },  {
    name: `Status`,    valuePath: `status`  },  // {  //   name: `Status Icons`,  //   valuePath: `status_icons`,  //   cellComponent: `custom-cell`,  //   color: `orange`  // },  {
    name: `Priority`,    valuePath: `priority`  }
];

ROws was defined
  get rowsForSortingNFiltering() {


    console.log('model.length', this.model[1].length);
    var rowsFiltered = this.model[1];    return rowsFiltered;
  }

Model was returned as below.
model() {
  let columns = this.dataGenerator.columns;  let filter = this.dataGenerator.workorderFilter;
  /* Whenever looping forever, 1. comment below >> 2. open inspect >> 3.uncomment */  return this.store.findAll('workorder').then(function(workOrders){
    debugger;
    // show some values    if (workOrders.length > 0) {
      console.log("1st workorder:" , workOrders.objectAt(0).id, workOrders.objectAt(0).first_name);    }
    let model = [columns, workOrders, filter];    return model;  });

}

Whenever page was frozen, I had to comment above model. Refresh page. Open Inspector. Uncomment to check the data again.


I tried to removing the hbs table part. >> working, page not frozen
{{!-- workorder list --}}  <div class='demo-container'>      <EmberTable as |t|>          <t.head @columns={{columnsForSorting}}
                  @sorts={{sorts}}
                  @onUpdateSorts={{action (mut sorts)}}
                  @widthConstraint='gte-container'                  @fillMode='first-column'                  as |h|>
              <h.row as |r|>                  <r.cell as |columnValue columnMeta|>                    {{#if showSortIndicator}}
                        <EmberTh::SortIndicator @columnMeta={{columnMeta}} />                    {{/if}}
                    {{columnValue.name}}
                    {{#if showResizeHandle}}
                        <EmberTh::ResizeHandle @columnMeta={{columnMeta}} />                    {{/if}}
                  </r.cell>              </h.row>          </t.head>
          <t.body @rows={{rowsForSortingNFiltering}} as |b|>              <b.row as |r|>                  <r.cell as |cell column|>                    {{#if column.cellComponent}}
                      {{#component column.cellComponent color=column.color statusIcons=cell}}
                      {{!-- {{cell}} --}}                      {{/component}}
                    {{else if (eq column.name "ID")}}
                        <a href="#" class="nav-button">{{cell}}</a>                    {{else}}
                      {{cell}}
                    {{/if}}
                  </r.cell>              </b.row>          </t.body>
      </EmberTable>  </div>

And tried to put each data without EmberTable >> working.
{{#each rowsForSortingNFiltering as |row| }}
  <div>{{row.id}} {{row.full_name}}  {{row.vip}}  {{row.problem}} {{row.dt_date_received}} {{row.dt_date_quoted}} {{row.dt_date_completion}} {{row.status}} {{row.priority}}</div>{{/each}}


Tried put simplest EmberTable >> not working. frozen again.
<EmberTable as |t|>    <t.head @columns={{columnsForSorting}} />    <t.body @rows={{rowsForSortingNFiltering}} /></EmberTable>


Now tried to return rows matching column data only. No extra attribute is defined. New Rows was defined.

  get rowsForSortingNFiltering() {


    console.log('model.length', this.model[1].length);
    var rows = this.model[1];

    var rowsFiltered = [];    rows.forEach(function (elemRaw) {
      var elem = { id: elemRaw.id, full_name: elemRaw.full_name};      rowsFiltered.push(elem);    })


    return rowsFiltered;
  } 

And it finally worked! EmberTable requires exactly same valuePath of columns and rows. Columns can be more valuePath than rows. The missing valuePath will show empty. But rows cannot have more attribute than columns. EmberTable stops working!



Saturday 9 May 2020

Lumen model extra attributes

Lumen php return extra model attribute

Laravel talks about the multators and asscessors, but I couldn't get it until I found the below link. Good one!

https://stackoverflow.com/questions/17232714/add-a-custom-attribute-to-a-laravel-eloquent-model-on-load



https://laravel.com/docs/7.x/eloquent-mutators

So, you can get "full_name" when it is not in the table column.


INstall Lumen on Ubuntu local machine

https://auth0.com/blog/developing-restful-apis-with-lumen/

Start Lumen installation from above site. Lumen home page was hopeless.
Install composer correctly. TRy to read how to install.

When I just copied folder from my Mac into Ubuntu and run local:8000 it showed below error.

Below was unnecessary?
I found that it was not actually MySQL user issue. But wrong id/password in the .env file. I must have set it at some point. Change it with correct user detail, and voila!


Next day, I had this error.



FRom google, I found the issue is symfony version, and I updated following.
https://stackoverflow.com/questions/58975559/symfony-component-debug-exception-fatalerrorexception-laravel-error

But I still had error below.

matthew@SYDNEY-D-003:~/work2/scr-webservice$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php ^7.2 but your PHP version (7.1.33) does not satisfy that requirement.
  Problem 2
    - laravel/lumen-framework v6.3.5 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
    - laravel/lumen-framework v6.3.4 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
    - laravel/lumen-framework v6.3.3 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
    - laravel/lumen-framework v6.3.2 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.


I found that LUmen requires Php7.2 and I have 7.1 in my ubuntu. I decided to update my php following below url.

https://www.liquidweb.com/kb/install-php-7-2-ubuntu-16-04/


But even after installing 7.2, it showed current version as 7.1. I don't know why. Because I followed above URL, my current apache is using Php7.2





Actually my issue was I was looking at /api/authors not /api/workorders. I don't know what to do now .asl;djf;sjadflks;jadlfj


Friday 8 May 2020

Setup MySQL on UBUNTU

MySQL Workbench was not the best tool in Ubuntu
- Ctrl-ENter sometimes ran previous query not current selected query
- Screen too big
- MOved to PHpSTorm


Open local host
Database >> +Datasource >> MySQL


Loading DOcument - MySQL Workbench

<Where is file>
Dropbox >> TechDoc_Cascade >> AWS_all >> sql
I don't know why I put it there.

<files>
migration1.sql
migtration2.sql


<how to import excel file>

1. COnvert customer's .xlsx file into .csv >> so much convenient later.

2. MySQL WOrkbench >> Server >> Data IMport >> select .csv file. (x)
2. Choose schema, eg, matthew_schema >> Tables >> right clikc >> 'Table Data IMport' (o)

3. Start import
4. Review 'text' data (date data should be exported to text data first for more peaceful import)
5. Keep the table name as raw, eg, JObLIst_import. We will keep this as reference, and create a new table any way.

6. ONce import is finished apply migration1.sql


<MySQL Workbench>
Edit >> Preference >> SQL Editor >> untic 'Safe UPdtes'
SQL Editor >> SQL Execution >> 'Limit ROws' >> 10,000


<Change root user password>
This site messed me up:
https://www.a2hosting.com/kb/developer-corner/mysql/reset-mysql-root-password

This site saved me:
https://stackoverflow.com/questions/30692812/mysql-user-db-does-not-have-password-columns-installing-mysql-on-osx

Below code of the 1st url seems to be old one.

matthew@SYDNEY-D-003:~/work2/$ mkdir -p /var/run/mysqld
mkdir: cannot create directory ‘/var/run/mysqld’: Permission denied
matthew@SYDNEY-D-003:~/work2/$ sudo mkdir -p /var/run/mysqld
matthew@SYDNEY-D-003:~/work2/$ chown mysql:mysql /var/run/mysqld
chown: changing ownership of '/var/run/mysqld': Operation not permitted
matthew@SYDNEY-D-003:~/work2/$ sudo chown mysql:mysql /var/run/mysqld
matthew@SYDNEY-D-003:~/work2/$ sudo mysqld_safe --skip-grant-tables &
[2] 19349
matthew@SYDNEY-D-003:~/work2/$ 2020-05-09T06:27:16.694377Z mysqld_safe Logging to syslog.
2020-05-09T06:27:16.698323Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2020-05-09T06:27:16.728153Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

<MySQL errors>
Access denied for user 'user'@'localhost' (using password: YES) (SQL: select * from `authors`)
>> create user

mysql seems no password required.
if 'mysql -u root -p' doesn't work with you root password you remeber, just type in 'mysql'.

 Even when I typed in correct password, it was returning error message.
ON the contrary, when I just typed in 'mysql', voila!!

 You could even update root user's password.