From 89c942b0d9f9345ca4f99c782504d1da7dc03cc8 Mon Sep 17 00:00:00 2001 From: guyben Date: Fri, 21 Sep 2018 09:00:45 -0700 Subject: [PATCH] Have a resource component receive the "registrar resource" instead of creating it We have several "consoles" ("views" in the registrar console). They all affect the same resource - the registrar itself. Currently, each view creates its own "RESTful resource", even though it's the same resource for all of them, meaning we have copied code and copied "URL endpoint" across multiple files. I assume this was made so that IF one day we have a "view" to another resource, we can easily add it. But we currently don't have any such view, nor plans to add any. So according to the YAGNI paradigm, it's better to move the resource creation outside of the console. Also, IF we do add a view to a different resource - it'll still be more readable to have a map from the "view" to the "resource URL endpoint" alongside the existing map from the "view" to the "console"... ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=213992967 --- java/google/registry/ui/js/registrar/console.js | 8 ++++++-- .../registry/ui/js/registrar/contact_settings.js | 12 ++++-------- java/google/registry/ui/js/registrar/contact_us.js | 13 ++++--------- java/google/registry/ui/js/registrar/resources.js | 13 ++++--------- .../registry/ui/js/registrar/security_settings.js | 13 ++++--------- .../registry/ui/js/registrar/whois_settings.js | 13 ++++--------- 6 files changed, 26 insertions(+), 46 deletions(-) diff --git a/java/google/registry/ui/js/registrar/console.js b/java/google/registry/ui/js/registrar/console.js index 99d8a4cfa..0796e0c5e 100644 --- a/java/google/registry/ui/js/registrar/console.js +++ b/java/google/registry/ui/js/registrar/console.js @@ -14,11 +14,13 @@ goog.provide('registry.registrar.Console'); +goog.require('goog.Uri'); goog.require('goog.dispose'); goog.require('goog.dom'); goog.require('goog.dom.classlist'); goog.require('goog.net.XhrIo'); goog.require('registry.Console'); +goog.require('registry.Resource'); goog.require('registry.registrar.Contact'); goog.require('registry.registrar.ContactSettings'); goog.require('registry.registrar.ContactUs'); @@ -76,7 +78,7 @@ registry.registrar.Console = function(params) { /** * @type {!Object.} + * !registry.Resource)>} */ this.pageMap = {}; this.pageMap['security-settings'] = registry.registrar.SecuritySettings; @@ -136,7 +138,9 @@ registry.registrar.Console.prototype.handleHashChange = function() { componentCtor = this.pageMap['']; } var oldComponent = this.component_; - this.component_ = new componentCtor(this, this.params.xsrfToken); + const resource = new registry.Resource( + new goog.Uri('/registrar-settings'), this.params.xsrfToken); + this.component_ = new componentCtor(this, resource); this.registerDisposable(this.component_); this.component_.basePath = type; this.component_.bindToDom(id); diff --git a/java/google/registry/ui/js/registrar/contact_settings.js b/java/google/registry/ui/js/registrar/contact_settings.js index 480155558..d690bc79a 100644 --- a/java/google/registry/ui/js/registrar/contact_settings.js +++ b/java/google/registry/ui/js/registrar/contact_settings.js @@ -14,7 +14,6 @@ goog.provide('registry.registrar.ContactSettings'); -goog.require('goog.Uri'); goog.require('goog.array'); goog.require('goog.dom'); goog.require('goog.dom.TagName'); @@ -38,18 +37,15 @@ goog.forwardDeclare('registry.registrar.Console'); * updating only that field of the Registrar object and not * implementing the create action from edit_item. * @param {!registry.registrar.Console} console - * @param {string} xsrfToken Security token to pass back to the server. + * @param {!registry.Resource} resource the RESTful resource for the registrar. * @constructor * @extends {registry.ResourceComponent} * @final */ -registry.registrar.ContactSettings = function(console, xsrfToken) { +registry.registrar.ContactSettings = function(console, resource) { registry.registrar.ContactSettings.base( - this, 'constructor', - console, - new registry.Resource(new goog.Uri('/registrar-settings'), xsrfToken), - registry.soy.registrar.contacts.contact, - null); + this, 'constructor', console, resource, + registry.soy.registrar.contacts.contact, null); }; goog.inherits(registry.registrar.ContactSettings, registry.ResourceComponent); diff --git a/java/google/registry/ui/js/registrar/contact_us.js b/java/google/registry/ui/js/registrar/contact_us.js index ae7870d0f..0d19c09ad 100644 --- a/java/google/registry/ui/js/registrar/contact_us.js +++ b/java/google/registry/ui/js/registrar/contact_us.js @@ -14,7 +14,6 @@ goog.provide('registry.registrar.ContactUs'); -goog.require('goog.Uri'); goog.require('goog.dom'); goog.require('registry.Resource'); goog.require('registry.ResourceComponent'); @@ -27,19 +26,15 @@ goog.forwardDeclare('registry.registrar.Console'); /** * Contact Us page. * @param {!registry.registrar.Console} console - * @param {string} xsrfToken Security token to pass back to the server. + * @param {!registry.Resource} resource the RESTful resource for the registrar. * @constructor * @extends {registry.ResourceComponent} * @final */ -registry.registrar.ContactUs = function(console, xsrfToken) { +registry.registrar.ContactUs = function(console, resource) { registry.registrar.ContactUs.base( - this, - 'constructor', - console, - new registry.Resource(new goog.Uri('/registrar-settings'), xsrfToken), - registry.soy.registrar.console.contactUs, - null); + this, 'constructor', console, resource, + registry.soy.registrar.console.contactUs, null); }; goog.inherits(registry.registrar.ContactUs, registry.ResourceComponent); diff --git a/java/google/registry/ui/js/registrar/resources.js b/java/google/registry/ui/js/registrar/resources.js index 003636b90..5f188a38d 100644 --- a/java/google/registry/ui/js/registrar/resources.js +++ b/java/google/registry/ui/js/registrar/resources.js @@ -14,7 +14,6 @@ goog.provide('registry.registrar.Resources'); -goog.require('goog.Uri'); goog.require('goog.dom'); goog.require('registry.Resource'); goog.require('registry.ResourceComponent'); @@ -27,19 +26,15 @@ goog.forwardDeclare('registry.registrar.Console'); /** * Resources and billing page. * @param {!registry.registrar.Console} console - * @param {string} xsrfToken Security token to pass back to the server. + * @param {!registry.Resource} resource the RESTful resource for the registrar. * @constructor * @extends {registry.ResourceComponent} * @final */ -registry.registrar.Resources = function(console, xsrfToken) { +registry.registrar.Resources = function(console, resource) { registry.registrar.Resources.base( - this, - 'constructor', - console, - new registry.Resource(new goog.Uri('/registrar-settings'), xsrfToken), - registry.soy.registrar.console.resources, - null); + this, 'constructor', console, resource, + registry.soy.registrar.console.resources, null); }; goog.inherits(registry.registrar.Resources, registry.ResourceComponent); diff --git a/java/google/registry/ui/js/registrar/security_settings.js b/java/google/registry/ui/js/registrar/security_settings.js index 849c8fb9a..1a3f2ed34 100644 --- a/java/google/registry/ui/js/registrar/security_settings.js +++ b/java/google/registry/ui/js/registrar/security_settings.js @@ -14,7 +14,6 @@ goog.provide('registry.registrar.SecuritySettings'); -goog.require('goog.Uri'); goog.require('goog.array'); goog.require('goog.dom'); goog.require('goog.dom.classlist'); @@ -32,19 +31,15 @@ goog.forwardDeclare('registry.registrar.Console'); /** * Security Settings page. * @param {!registry.registrar.Console} console - * @param {string} xsrfToken Security token to pass back to the server. + * @param {!registry.Resource} resource the RESTful resource for the registrar. * @constructor * @extends {registry.ResourceComponent} * @final */ -registry.registrar.SecuritySettings = function(console, xsrfToken) { +registry.registrar.SecuritySettings = function(console, resource) { registry.registrar.SecuritySettings.base( - this, - 'constructor', - console, - new registry.Resource(new goog.Uri('/registrar-settings'), xsrfToken), - registry.soy.registrar.security.settings, - null); + this, 'constructor', console, resource, + registry.soy.registrar.security.settings, null); }; goog.inherits(registry.registrar.SecuritySettings, registry.ResourceComponent); diff --git a/java/google/registry/ui/js/registrar/whois_settings.js b/java/google/registry/ui/js/registrar/whois_settings.js index 7234c5117..68297dbb7 100644 --- a/java/google/registry/ui/js/registrar/whois_settings.js +++ b/java/google/registry/ui/js/registrar/whois_settings.js @@ -14,7 +14,6 @@ goog.provide('registry.registrar.WhoisSettings'); -goog.require('goog.Uri'); goog.require('goog.dom'); goog.require('registry.Resource'); goog.require('registry.ResourceComponent'); @@ -27,19 +26,15 @@ goog.forwardDeclare('registry.registrar.Console'); /** * WHOIS Settings page. * @param {!registry.registrar.Console} console - * @param {string} xsrfToken Cross-site request forgery protection token. + * @param {!registry.Resource} resource the RESTful resource for the registrar. * @constructor * @extends {registry.ResourceComponent} * @final */ -registry.registrar.WhoisSettings = function(console, xsrfToken) { +registry.registrar.WhoisSettings = function(console, resource) { registry.registrar.WhoisSettings.base( - this, - 'constructor', - console, - new registry.Resource(new goog.Uri('/registrar-settings'), xsrfToken), - registry.soy.registrar.whois.settings, - null); + this, 'constructor', console, resource, + registry.soy.registrar.whois.settings, null); }; goog.inherits(registry.registrar.WhoisSettings, registry.ResourceComponent);