Skip to content

Commit

Permalink
fix(ui): display refresh banner on new ui deployed (#4913)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault committed Jan 23, 2020
1 parent 091af27 commit a3bb926
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion engine/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Configuration struct {
Name string `toml:"name" comment:"Name of this CDS API Service\n Enter a name to enable this service" json:"name"`
URL struct {
API string `toml:"api" default:"http://localhost:8081" json:"api"`
UI string `toml:"ui" default:"http://localhost:2015" json:"ui"`
UI string `toml:"ui" default:"http://localhost:8080" json:"ui"`
} `toml:"url" comment:"#####################\n CDS URLs Settings \n####################" json:"url"`
HTTP struct {
Addr string `toml:"addr" default:"" commented:"true" comment:"Listen HTTP address without port, example: 127.0.0.1" json:"addr"`
Expand Down
21 changes: 10 additions & 11 deletions engine/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ func (s *Service) CheckConfiguration(config interface{}) error {
}

// Serve will start the http ui server
func (s *Service) Serve(c context.Context) error {
log.Info(c, "ui> Starting service %s %s...", s.Cfg.Name, sdk.VERSION)
func (s *Service) Serve(ctx context.Context) error {
log.Info(ctx, "ui> Starting service %s %s...", s.Cfg.Name, sdk.VERSION)
s.StartupTime = time.Now()

fromTmpl, err := s.prepareIndexHTML()
if err != nil {
return err
}

if err := s.checkStaticFiles(c); err != nil {
if err := s.checkStaticFiles(ctx); err != nil {
return err
}

Expand All @@ -119,7 +119,7 @@ func (s *Service) Serve(c context.Context) error {
}

//Init the http server
s.initRouter(c)
s.initRouter(ctx)
server := &http.Server{
Addr: fmt.Sprintf("%s:%d", s.Cfg.HTTP.Addr, s.Cfg.HTTP.Port),
Handler: s.Router.Mux,
Expand All @@ -129,19 +129,19 @@ func (s *Service) Serve(c context.Context) error {
}

// Start the http server
log.Info(c, "ui> Starting HTTP Server on port %d", s.Cfg.HTTP.Port)
log.Info(ctx, "ui> Starting HTTP Server on port %d", s.Cfg.HTTP.Port)
if err := server.ListenAndServe(); err != nil {
log.Error(c, "ui> Listen and serve failed: %s", err)
log.Error(ctx, "ui> Listen and serve failed: %s", err)
}

// Gracefully shutdown the http server
<-c.Done()
log.Info(c, "ui> Shutdown HTTP Server")
if err := server.Shutdown(c); err != nil {
<-ctx.Done()
log.Info(ctx, "ui> Shutdown HTTP Server")
if err := server.Shutdown(ctx); err != nil {
return fmt.Errorf("unable to shutdown server: %v", err)
}

return c.Err()
return ctx.Err()
}

// checkChecksumFiles checks the sha512 values.
Expand Down Expand Up @@ -235,7 +235,6 @@ func (s *Service) indexHTMLReplaceVar() error {
indexContent := regexBaseHref.ReplaceAllString(string(read), "<base href=\""+s.Cfg.BaseURL+"\">")
indexContent = strings.Replace(indexContent, "window.cds_sentry_url = '';", "window.cds_sentry_url = '"+s.Cfg.SentryURL+"';", -1)
indexContent = strings.Replace(indexContent, "window.cds_version = '';", "window.cds_version='"+sdk.VERSION+"';", -1)

return ioutil.WriteFile(indexHTML, []byte(indexContent), 0)
}

Expand Down
2 changes: 1 addition & 1 deletion engine/vcs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Configuration struct {
URL string `default:"http://localhost:8084" json:"url"`
UI struct {
HTTP struct {
URL string `toml:"url" default:"http://localhost:2015" json:"url"`
URL string `toml:"url" default:"http://localhost:8080" json:"url"`
} `toml:"http" json:"http"`
} `toml:"ui" json:"ui"`
API service.APIServiceConfiguration `toml:"api" comment:"######################\n CDS API Settings \n######################" json:"api"`
Expand Down
7 changes: 1 addition & 6 deletions ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class AppComponent implements OnInit {
sseWorker: CDSWorker;
heartbeatToken: number;
zone: NgZone;
currentVersion = 0;
showUIUpdatedBanner: boolean;
languageSubscriber: Subscription;
themeSubscriber: Subscription;
Expand Down Expand Up @@ -262,11 +261,7 @@ export class AppComponent implements OnInit {
this.versionWorker.response().subscribe(msg => {
if (msg) {
this.zone.run(() => {
let versionJSON = Number(JSON.parse(msg).version);
if (this.currentVersion === 0) {
this.currentVersion = versionJSON;
}
if (this.currentVersion < versionJSON) {
if ((<any>window).cds_version !== '' && (<any>window).cds_version !== JSON.parse(msg).version) {
this.showUIUpdatedBanner = true;
}
});
Expand Down

0 comments on commit a3bb926

Please sign in to comment.