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.





Monday, 27 April 2020

Simplest CRUD - Ember web service (Web API) tutorial

Ember adapters
https://guides.emberjs.com/v3.15.0/models/customizing-adapters/

Serializer
https://guides.emberjs.com/v3.15.0/models/customizing-serializers/

The tutorial
https://medium.com/ember-ish/the-simplest-possible-ember-data-crud-16eacee33ae6

I am following the above tutorial...(27/4/20)

API + db all working well.


CORS issue was also fixed by using middleware.

Enable CORS in Lumen




But I still had issue in GET operation


The lady author says,

"If your POST request failed and this surprises you, a few different things could be wrong:"

I guess the issue is the json format.
https://guides.emberjs.com/v3.15.0/models/customizing-serializers/

My guess was right. Ember serializer default is JsonWAPISerializer. You have to change it to JsonSerializer to work with Lumen's default json formats without 'data' or 'attribute' name conventions.



Now /api/boardgames/1 is working.





But insert is still not working. Why?


Amazingly, the issue was in database. The sample Lumen API server code (not this tutorial) I downloaded from below required updated_at, created_at in each table. After updating the database, POST call to create new boardgame worked fine!!

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




Now insert is working




16/5/20. At one stage, insert stopped working again, this time with CORS issue again.  My table had two date columns, middle ware was there (GET was still working). I found suspecious error in Lumen console. It seems my PHP in LInux(7.1) is not good enough for SImpony (lumen insert operation). The same code was working on my mac (php 7.2) fine?





 Why Delete not working?


I know it is an API error while returning the result. because when I refreshed the page, the record was deleted already. And it didn't show any error while debugging. Debugging was a bit tricky to find where to see.


Web API returns string and it was not a correct JSON format. You have to implement Ember serializer.

public function delete($id)
{
BoardGame::findOrFail($id)->delete();
return response('Deleted Successfully', 200);
}

As soon as I change Web API delete as below, Ember site started working.

https://stackoverflow.com/questions/28387693/ember-promise-destroyrecord-then-failing-on-successful-request



public function delete($id)
{
BoardGame::findOrFail($id)->delete();
//return response('Deleted Successfully', 200);
//below is working as well. but you don't seem to get $newContent.
// $newContent = [
// 'data' => 'deleted'
// ];
// return response()->json($newContent, 200);
//https://stackoverflow.com/questions/28387693/ember-promise-destroyrecord-then-failing-on-successful-request
return response('Deleted Successfully', 204);
}



Why update not working?



I found that Ember translates updates as 'PATCH' operation.

  • I tried PATCH in postman it didn't work. 
  • Also PUT operation had to use www-encode option (?). 
  • There must be something special about PUT operation. 
  • Google search 'ember use PUT instead of PATCH'. Then the below link, the 1st solution worked for me not the second. 
  • So you have to convert PATCH to PUT operation with below code
  • app/adapters/application.js


https://github.com/emberjs/data/issues/3870

export default DS.JSONAPIAdapter.extend({
host: 'http://localhost:8000/api',
updateRecord: function (store, type, snapshot) {
var data = {};
var serializer = store.serializerFor(type.modelName);
serializer.serializeIntoHash(data, type, snapshot, { includeId: true });
var id = snapshot.id;
var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord');
return this.ajax(url, 'PUT', { data: data });
}
})

Summary

Make sure you put model() hook in the router not controller js.

Here is the completed Ember web API, the simplest one:
https://github.com/oneman93/ember-simplest-crud


I like to share my web service API as well, but because I did update in there for my personal stuff, I cannot share it. However, the Lumen tutorial above will be enough to start up a web service server.

-----------

Webservice other urls

youtube about ember data
https://www.youtube.com/watch?v=ljLxZw-XStw

mirage tutorial
https://guides.emberjs.com/v3.4.0/tutorial/ember-data/


Friday, 3 April 2020

ember-modal-dialog

https://github.com/yapplabs/ember-modal-dialog#live-demo-and-test-examples

Followed the link.
1. Installed the ember-modal-dialog inside ember project folder.
2. Restarted ember - ember s
3. Page refresh. hola!

Thursday, 2 April 2020

git tag

Create git tag in old commit

I like to add git tag to one of my old commits, say, e9c4a35.

% git tag                
% git tag -a v1.0 e9c4a35
or 
% git tag -a v1.0 e9c4a35 -m 'multi page complete'

% git tag                
v1.0

Then you push the tag to remote server

% git push origin v1.0
Enumerating objects: 1, done.

Now your github site will have this tag.
See more in
or
visual github

How to create remote git tag without local tag with hash code, I don't know.

<annotated vs non-annotated tag>

When you use git tag <tagname>, Git will create a tag at the current revision but will not prompt you for an annotation. It will be tagged without a message (this is a lightweight tag).

When you use git tag -a <tagname>, Git will prompt you for an annotation unless you have also used the -m flag to provide a message.


https://stackoverflow.com/questions/11514075/what-is-the-difference-between-an-annotated-and-unannotated-tag



<git describe>

The command finds the most recent tag that is reachable from a commit. If the tag points to the commit, then only the tag is shown. Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit.

By default (without --all or --tags) git describe only shows annotated tags

https://git-scm.com/docs/git-describe

<git describe --tags>

It shows any tag found in refs/tags namespace. This option enables matching a lightweight (non-annotated) tag.

If the environment is on a branch that is 14 commits ahead of the last tag, this will show, eg, v0.0.1-14-gXXX, where XXX is SHA hash value.

https://git-scm.com/docs/git-describe
https://www.soliantconsulting.com/blog/versioning-with-git-describe/


<git push with tag>

By default, the git push command doesn’t transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches — you can run git push origin <tagname>.

https://git-scm.com/book/en/v2/Git-Basics-Tagging
https://stackoverflow.com/questions/5195859/how-do-you-push-a-tag-to-a-remote-repository-using-git




<problem with git describe --tags>
 git push -f origin CE-7757

I pushed without tag, but it still prints tag information.


#!/bin/bash -eo pipefail
echo "$(git describe --tags)"
echo 'cur_version=$(git describe --tags)' >> $BASH_ENV
v0.0.1-7-g6e4a85b4f




<CIRCLE_TAG is empty>

https://discuss.circleci.com/t/circle-tag-is-empty/18919?utm_medium=SEM&utm_source=gnb&utm_campaign=SEM-gb-DSA-Eng-ni&utm_content=&utm_term=dynamicSearch-&gclid=EAIaIQobChMI0f2W_OnG6AIVRw4rCh2lhAxYEAAYASAAEgLsOPD_BwE

https://support.circleci.com/hc/en-us/articles/360020342494-The-built-in-environment-variable-CIRCLE-TAG-is-not-present


<git push - NO BRANCH BUT TAG???>


git push without parameter
https://stackoverflow.com/questions/948354/default-behavior-of-git-push-without-a-branch-specified

<example>

$ git commit -a -m 'test v0.0.0'
[CE-7757 334779fbc] test v0.0.0
 1 file changed, 2 insertions(+), 2 deletions(-)
$ git tag v0.0.0
$ git describe --tags
v0.0.0

$ git commit -a -m 'test v0.0.1'
[CE-7757 d077f2b85] test v0.0.1
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git tag v0.0.1
$ git describe --tags
v0.0.1

$ git push origin CE-7757 v0.0.0
Counting objects: 8, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (8/8), 763 bytes | 763.00 KiB/s, done.
Total 8 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 2 local objects.
To github.com:xxx.git
   97635f5ee..d077f2b85  CE-7757 -> CE-7757
 * [new tag]             v0.0.0 -> v0.0.0





After the push, search by branch and tag will give you different point of HEAD.






Also, note the push result. Circleci does not returns v0.0.0 but v0.0.0-1-gxxx because the 'git describe --tags' will return 'the most recent tag reachable from the commit'. Considering entire commits, current commit was 1 time after the tag commit. The server github does not have any idea about v0.0.1 yet, but knows that the last commit (by branch) is 1 time after the tag's commit. So...the same command 'git describe --tags' can show different result when you run it on local machine and remote circle ci environment (if you use different tag on push).