Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1etYoJ-0007WQ-GE for pgadmin-hackers@arkaria.postgresql.org; Wed, 07 Mar 2018 13:08:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1etYoH-0000KZ-Ob for pgadmin-hackers@arkaria.postgresql.org; Wed, 07 Mar 2018 13:08:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1etYoH-0000KP-He for pgadmin-hackers@lists.postgresql.org; Wed, 07 Mar 2018 13:08:45 +0000 Received: from mail-ot0-x242.google.com ([2607:f8b0:4003:c0f::242]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1etYoC-0007pi-Bp for pgadmin-hackers@postgresql.org; Wed, 07 Mar 2018 13:08:44 +0000 Received: by mail-ot0-x242.google.com with SMTP id n74so1976025ota.1 for ; Wed, 07 Mar 2018 05:08:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=cOgjDDWfCw9j1nUnGxqBlBI8bITWTMDrO8hGqSgsf48=; b=K5dzL2sMHctgF/08XGXy5LYalpM36Ne6wQRAa2CbT/Gthl3zplmD3lyQMu0nnNIv4L 0RywVyEvRlxqN4rp6ejrx+MIHXVTwr6D2ORb2pe/A3T4m7vCfUgaBVwnJUvmLIaisL90 Om2XEbdKD4NWTS0KDq6uHN1g7N3oI0Izn7tSmmqTU9wXPi28UHnl7fCKDKbg5Bw6rSy1 AWzSvCuGMja3NPrmofAEhe+xCe9xUmQpmWhm58Ucq/gzl7kHMsJYAmU9KD/rFBiTmNX6 akcOTj63zQLevJzdXDv73BpUGL9nLmywXOtj+B7m6jnsQ3PTTiiU7Zzajw5BkEYzPNO/ SNcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=cOgjDDWfCw9j1nUnGxqBlBI8bITWTMDrO8hGqSgsf48=; b=N3Pvrbkhzr265/FX0z/4Gw9W94kKaZYTZ7L7YMR7ATzbC6E0F32L+xt3932vOq78I4 nysMgKXOlT74WQnVPDt+K0Q2mMk7Yvr6bs2WlRGP8wpEFjoj7FWwovQpGhgnFDZYOVtD uen41zR4LFlZ6zMrxOTpprIFtC+69BM+RxCzeEpvPSzHIK9kdDIG7fySwvsnt7CLuvMu RvUJqGzUzSlWHiEK5Sbom9/lW+IwnwHCNGIYhQ06eFFEgtakgvF8MQHX30nv17nngUTe bUYZpru6jNnW9OLZVeOgyPs5zyODQvF7Dh9EJjutXcqtILE1OH3Df4fhTo8sckzsh9Bk iEWg== X-Gm-Message-State: AElRT7FcQu6y6/n18sBTRzOGcZZcRpvF87HOQqhbxM4gRIuWWQst3KDH xY3xYi913YreRSNn1SURRQRVWduNOKdfyMH0d9wGpw== X-Google-Smtp-Source: AG47ELtus0Ju5CORWesmgcqm6WhDpzMcCBmjotYOwwcSlXtCDdHYLbAWepx6Zr3Z+GqpYyo3YcZXOmMStlhbbDtkrRQ= X-Received: by 10.157.31.82 with SMTP id x18mr14950724otx.291.1520428117866; Wed, 07 Mar 2018 05:08:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.8.150 with HTTP; Wed, 7 Mar 2018 05:08:17 -0800 (PST) In-Reply-To: References: From: Murtuza Zabuawala Date: Wed, 7 Mar 2018 18:38:17 +0530 Message-ID: Subject: Re: [pgAdmin4][RM#3037] Allow user to disable Gravatar image To: Joao De Almeida Pereira Cc: Dave Page , pgadmin-hackers Content-Type: multipart/alternative; boundary="001a113dd2dedf5c320566d241ae" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --001a113dd2dedf5c320566d241ae Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Joao, On Tue, Mar 6, 2018 at 10:56 PM, Joao De Almeida Pereira < jdealmeidapereira@pivotal.io> wrote: > Hello, > > I just sent a video that talks exactly about this, in the journey to have > a more maintainable code and easier to navigate, we sometimes increase > complexity for a period of time in order to get to the state that we want > to be. > > In particular in this example I tried the following: > 1. Demonstrate that we do not need templates to get things done > That raised questions in mind, =E2=80=8BWhy? =E2=80=8B I =E2=80=8Bf templates are bad then why every other framework provides them? I've seen many projects using templates to serve HTML code, In pgAdmin4 also we are using templates just as starting point to load UI whether its main page or query tool/debugger page. 2. How to get the information we need to the place where it is needed, like > moving the information of the server mode to the front end where decision= s > should be made > =E2=80=8BI agree and that's what we are doing in pgAdmin4. > =E2=80=8B > > > Sometimes just because we can do a simple change, doesn't mean we should > do it because it might bit us in the future. > > > The PoC looks like a huge amount of code that is not even related to > Gravatar, when we could just change a template file or 2, I hear that. Bu= t > what I am talking about is a change of paradigm and Architecture where th= e > Frontend is responsible for displaying the application and the Backend is > only responsible for giving information that the Frontend Requires. Inste= ad > of the current mixed architecture where some things are done in the > Frontend some things are done in the Backend a more predictable > architecture would benefit the application and specially the developers. > =E2=80=8B > > > That is why I always insist in refactor code as much as possible to ensur= e > that the code is readable and helps people follow it. This doesn't mean > abstracting classes of functions to make to code more generic, it means a= s > an example to split 1 functions of 500 lines into 10 functions of 50 line= s > each or even 50 functions of 10 lines each but that are readable and not = a > "goat trails" of ifs and elses that are very hard to read and follow. > =E2=80=8BI =E2=80=8Btotally =E2=80=8B agree that refacto =E2=80=8Bring=E2=80=8B code is good practice but in this =E2=80=8Bparticular =E2=80=8B case I =E2=80=8Bstill =E2=80=8B think =E2=80=8Bthat =E2=80=8B using =E2=80=8BHTML =E2=80=8B template is =E2=80=8Bmuch =E2=80=8B simpler and elegant solution =E2=80=8B.=E2=80=8B > > > Thanks > Joao > > On Tue, Mar 6, 2018 at 4:49 AM Dave Page wrote: > >> Hi >> >> On Tue, Mar 6, 2018 at 6:59 AM, Murtuza Zabuawala > enterprisedb.com> wrote: >> >>> Hi Joao, >>> >>> Your suggestion is good but in my own opinion it is overkill just to >>> replace code {{ username| gravatar }} as rest of the syntax is pure >>> HTML, This makes code much simpler and easy to understand. >>> Apart from that we will be rendering 'index.html' template anyways and = I >>> don't see any extra overhead. >>> >> >> For this particular issue, I'm inclined to agree. >> >> I do however, like the idea of caching preferences (no-brainer really, >> assuming we ensure we update/invalidate the cache when needed), and usin= g >> promises for accessing them. >> >> >>> >>> I may be wrong, Let's wait for the input from other community members. >>> >>> Regards, >>> Murtuza >>> >>> On Tue, Mar 6, 2018 at 1:17 AM, Joao De Almeida Pereira < >>> jdealmeidapereira@pivotal.io> wrote: >>> >>>> Hello, >>>> I understand that, but what do we win by using it? As you have noticed >>>> by now I am not very fond of using templates for everything, and I bel= ieve >>>> this is one of the things that we can skip templates. >>>> We might even shift this to a frontend concern and if we want there ar= e >>>> node libraries to get gravatars. >>>> >>>> I was able to create a PoC as a sample of what I was talking about: >>>> - Add gravatar library to package.json >>>> - Created a Preferences cache. (js/preferences.js) >>>> - So this was the concept I was talking about in a previous email w= e >>>> talked about caching. >>>> the getConfiguration and the getAllConfiguration are not great >>>> names, but they return a Promise that is consumed in the load_gravatar= . The >>>> idea here is that we are caching the pgAdmin settings and when need ne= ed to >>>> consume them, we wait for it to be available. >>>> - load_gravatar is using the pattern to retrieve the configuration >>>> from a possible cache and then apply the gravatar >>>> >>>> >>>> Things that need to be revisited in the PoC: >>>> - No tests, just some spiked code >>>> - Did not retrieve the username from the backend, we need to create an >>>> endpoint that give us this >>>> - The url is hardcoded to get the configuration >>>> - Maybe the Preferences is not the correct place to get server_mode >>>> configuration not sure, what do you think? >>>> >>>> >>>> Thanks >>>> Joao >>>> >>>> On Mon, Mar 5, 2018 at 11:21 AM Murtuza Zabuawala >>> enterprisedb.com> wrote: >>>> >>>>> Hi Joao, >>>>> >>>>> We are using Flask-Gravatar >>>>> module for this and it is designed to work with template only. >>>>> >>>>> -- >>>>> Regards, >>>>> Murtuza Zabuawala >>>>> EnterpriseDB: http://www.enterprisedb.com >>>>> The Enterprise PostgreSQL Company >>>>> >>>>> >>>>> On Mon, Mar 5, 2018 at 8:57 PM, Joao De Almeida Pereira < >>>>> jdealmeidapereira@pivotal.io> wrote: >>>>> >>>>>> Hi Murtuza, >>>>>> >>>>>> Why are we doing this using templates? Can this be done with a >>>>>> request to the backend to get the image and then retrieve the Gravat= ar if >>>>>> it is defined or return a static image if not? >>>>>> >>>>>> + >>>>>> +{% if config.SERVER_MODE %} >>>>>> window.onload =3D function(e){ >>>>>> setTimeout(function() { >>>>>> - var gravatarImg =3D '>>>>> width=3D"18" height=3D"18" alt=3D"Gravatar image for {{ username }}"= > {{ username >>>>>> }} '; >>>>>> + var gravatarImg =3D {{ IMG.PREPARE_HTML()|safe }} >>>>>> //$('#navbar-menu .navbar-right > li > a').html(gravatarImg); >>>>>> var navbarRight =3D document.getElementById("navbar-menu"). >>>>>> getElementsByClassName("navbar-right")[0]; >>>>>> if (navbarRight) { >>>>>> >>>>>> what if we have >>>>>> >>>>>> var gravatarImg =3D '>>>>> height=3D"18" alt=3D"Gravatar image for {{ username }}"> {{ username= }} >>>>> class=3D"caret">'; >>>>>> >>>>>> And then the endpoint >>>>>> /user/{{username}}/gravatar >>>>>> would be responsible for returning a Gravatar or not depending on th= e >>>>>> configuration? >>>>>> >>>>>> >>>>>> Thanks >>>>>> Joao >>>>>> >>>>>> On Mon, Mar 5, 2018 at 3:13 AM Murtuza Zabuawala >>>>> enterprisedb.com> wrote: >>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> PFA patch to disable Gravatar image in Server mode. >>>>>>> >>>>>>> Requirments & Issues: >>>>>>> - For security reasons. >>>>>>> - For systems which do not have internet access. >>>>>>> - Hangs pgAdmin4 while loading the page if connection has no >>>>>>> internet access (as described in the ticket) >>>>>>> >>>>>>> -- >>>>>>> Regards, >>>>>>> Murtuza Zabuawala >>>>>>> EnterpriseDB: http://www.enterprisedb.com >>>>>>> The Enterprise PostgreSQL Company >>>>>>> >>>>>>> >>>>> >>> >> >> >> -- >> Dave Page >> Blog: http://pgsnake.blogspot.com >> Twitter: @pgsnake >> >> EnterpriseDB UK: http://www.enterprisedb.com >> The Enterprise PostgreSQL Company >> > --001a113dd2dedf5c320566d241ae Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Joao,

On Tue, Mar 6, 2018 at 10:56 PM, Joao De Alm= eida Pereira <jdealmeidapereira@pivotal.io> wrote= :
Hel= lo,

I just sent a video that talks exactly about this, i= n the journey to have a more maintainable code and easier to navigate, we s= ometimes increase complexity for a period of time in order to get to the st= ate that we want to be.

In particular in this exam= ple I tried the following:
1. Demonstrate that we do not need tem= plates to get things done
That raised questions in mind,=C2=A0
=E2=80=8BWhy?
=E2=80=8B
I
=E2=80=8Bf templates are bad then why every other framework pro= vides them?
I've seen man= y projects using templates to serve HTML code, In pgAdmin4 also we are usin= g templates just as starting point to load UI whether its main page or quer= y tool/debugger page.

2. How to get the information we need to the place where it is needed= , like moving the information of the server mode to the front end where dec= isions should be made

=E2=80=8BI agree a= nd that's what we are doing in pgAdmin4.
=E2=80=8B
=C2=A0

Somet= imes just because we can do a simple change, doesn't mean we should do = it because it might bit us in the future.


The PoC looks like a huge amount of code that is not even related to= Gravatar, when we could just change a template file or 2, I hear that. But= what I am talking about is a change of paradigm and Architecture where the= Frontend is responsible for displaying the application and the Backend is = only responsible for giving information that the Frontend Requires. Instead= of the current mixed architecture where some things are done in the Fronte= nd some things are done in the Backend a more predictable architecture woul= d benefit the application and specially the developers.
=E2=80=8B
=C2=A0

That = is why I always insist in refactor code as much as possible to ensure that = the code is readable and helps people follow it. This doesn't mean abst= racting classes of functions to make to code more generic, it means as an e= xample to split 1 functions of 500 lines into 10 functions of 50 lines each= or even 50 functions of 10 lines each but that are readable and not a &quo= t;goat trails"=C2=A0of ifs and elses that are very hard to read and fo= llow.

=C2=A0=E2=80=8BI
=E2=80=8Btotally =E2=80=8B
agree that=C2=A0refacto
=E2=80=8Bring=E2=80=8B
code is good practice but in thi= s
=E2=80=8Bparticular=C2=A0=E2=80= =8B
case I=
=E2=80=8Bstill =E2=80=8B
think
=E2=80=8Bthat =E2=80=8B
using
=E2=80=8BHTML =E2= =80=8B
template is
=E2=80=8Bmuch = =E2=80=8B
simpler= and elegant solution
=E2=80=8B.=E2=80= =8B


Thanks
Joa= o

On Tue, Mar 6,= 2018 at 4:49 AM Dave Page <dpage@pgadmin.org> wrote:
Hi

On Tue, Mar 6, 2018 at 6:5= 9 AM, Murtuza Zabuawala <murtuza.zabuawala@enterpris= edb.com> wrote:
Hi Joao,

= Your suggestion is goo= d but in my own opinion it is overkill just to replace code=C2=A0{{ username| gravatar }}=C2=A0as rest of the syntax=C2=A0is pure HTML, This makes code much = simpler and easy to understand.
Apart from that we will be renderi= ng 'index.html' template anyways and I don't see any extra over= head.

= For this particular issue, I'm inclined to agree.

<= div>I do however, like the idea of caching preferences (no-brainer really, = assuming we ensure we update/invalidate the cache when needed), and using p= romises for accessing them.
=C2=A0

I may be wrong, Let's w= ait for the input from other community members.

Regards,=C2=A0
Murtuza

On Tue, Mar 6, 2018 at 1:17 AM, Joao De Alme= ida Pereira <jdealmeidapereira@pivotal.io> wrote:=
Hello,
I understand that, but what do we win by using it? As you have= noticed by now I am not very fond of using templates for everything, and I= believe this is one of the things that we can skip templates.=C2=A0
We= might even shift this to a frontend concern and if we want there are node = libraries to get gravatars.

I was able to create a= PoC as a sample of what I was talking about:
=C2=A0- Add gravata= r library to package.json
=C2=A0- Created a Preferences cache. (j= s/preferences.js)
=C2=A0 =C2=A0- So this was the concept I was ta= lking about in a previous email we talked about caching.
=C2=A0 = =C2=A0 =C2=A0 the getConfiguration and the getAllConfiguration are not grea= t names, but they return a Promise that is consumed in the load_gravatar. T= he idea here is that we are caching the pgAdmin settings and when need need= to consume them, we wait for it to be available.
=C2=A0- load_gr= avatar is using the pattern to retrieve the configuration from a possible c= ache and then apply the gravatar


Th= ings that need to be revisited in the PoC:
- No tests, just some = spiked code
- Did not retrieve the username from the backend, we = need to create an endpoint that give us this
- The url is hardcod= ed to get the configuration
- Maybe the Preferences is not the co= rrect place to get server_mode configuration not sure, what do you think?


Thanks
Joao

On Mon, Mar 5, 2018 at 11= :21 AM Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> w= rote:
= Hi Joao,

We are using Flask-Gravatar module for this and it is designed to wor= k with template only.

= --
Regards,
Murtuza Zabuawala
EnterpriseDB:=C2=A0http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Mar= 5, 2018 at 8:57 PM, Joao De Almeida Pereira <jdealmeidapereir= a@pivotal.io> wrote:
Hi Murtuza,

Why are we doi= ng this using templates? Can this be done with a request to the backend to = get the image and then retrieve the Gravatar if it is defined or return a s= tatic image if not?

+
+{% if config= .SERVER_MODE %}
=C2=A0window.onload =3D function(e){
= =C2=A0 setTimeout(function() {
-=C2=A0 =C2=A0var gravatarImg =3D = '<img src=3D"{{ username | gravatar }}" width=3D"18&q= uot; height=3D"18" alt=3D"Gravatar image for {{ username }}&= quot;> {{ username }} <span class=3D"caret"></span>= ;';
+=C2=A0 =C2=A0var gravatarImg =3D {{ IMG.PREPARE_HTML()|s= afe }}
=C2=A0 =C2=A0 //$('#navbar-menu .navbar-right > li = > a').html(gravatarImg);
=C2=A0 =C2=A0 var navbarRight =3D= document.getElementById("navbar-menu").getElementsByCl= assName("navbar-right")[0];
=C2=A0 =C2=A0 if (navb= arRight) {

what if we have=C2=A0
<= br>
var gravatarImg =3D '<img src=3D"/user/{{username= }}/gravatar" width=3D"18" height=3D"18" alt= =3D"Gravatar image for {{ username }}"> {{ username }} <spa= n class=3D"caret"></span>';

=
And then the endpoint
/user/{{username}}/gravatar=C2=A0
would be responsible for returning a Gravatar or not depending on the= configuration?


Thanks
Jo= ao

On Mon, Mar 5= , 2018 at 3:13 AM Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.co= m> wrote:
Hi,

PFA patch to disable Gravatar image in Server mode.

Requirments &= ; Issues:
- For security reasons.
- F= or systems which do not have internet access.
- Hangs pgAdmin4 while l= oading the page if connection has no internet access (as described in the t= icket)

=
--
Regards,
<= font size=3D"2">Murtuz= a Zabuawala
EnterpriseDB:=C2=A0http://www.enterprisedb.comThe Enterprise PostgreSQL Company



<= font color=3D"#888888">



--
Dave Page
Blog: http://pgsnake.blogspot.com<= br>Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterpri= se PostgreSQL Company

--001a113dd2dedf5c320566d241ae--