Hello,

please review attached patches which add WebUI part of DNS Locations feature.


--
Pavel^3 Vomacka
From b2e30e910608d8be549e126889ff9a011149f58b Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvoma...@redhat.com>
Date: Sun, 5 Jun 2016 18:03:17 +0200
Subject: [PATCH 1/2] Add adapter attribute for choosing record

The new attribute of the adapter contains the name of record which will be
extracted from API call result.

Part of: https://fedorahosted.org/freeipa/ticket/5905
---
 install/ui/src/freeipa/field.js | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/install/ui/src/freeipa/field.js b/install/ui/src/freeipa/field.js
index fdf925e3d7adc62622e0c9e5e1440eefbdac807b..12ef7f45585802c4099e469c9fb5188b3a3587ab 100644
--- a/install/ui/src/freeipa/field.js
+++ b/install/ui/src/freeipa/field.js
@@ -802,6 +802,13 @@ field.Adapter = declare(null, {
     result_index: 0,
 
     /**
+     * Name of the record which we want to extract from the result.
+     * Used in dnslocations.
+     * @type {String}
+     */
+    result_name: 'result',
+
+    /**
      * Extract record from RPC call response
      *
      * Tries to detect if supplied data is RPC call response if so, it
@@ -821,10 +828,10 @@ field.Adapter = declare(null, {
         var dr = data.result;
         var record = null;
         if (dr) {
-            if (IPA.defined(dr.result)) record = dr.result;
+            if (IPA.defined(dr[this.result_name])) record = dr[this.result_name];
             else if (dr.results) {
                 var result = dr.results[this.result_index];
-                if (result) record = result.result;
+                if (result) record = result[this.result_name];
             }
         }
         return record;
-- 
2.5.5

From d0508eb4e5713277dd87dfa4a72baaf7909460d5 Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvoma...@redhat.com>
Date: Sun, 5 Jun 2016 18:07:29 +0200
Subject: [PATCH 2/2] DNS Locations: WebUI part

WebUI part of DNS Location feature.

https://fedorahosted.org/freeipa/ticket/5905
---
 install/ui/src/freeipa/navigation/menu_spec.js |   5 +
 install/ui/src/freeipa/topology.js             | 242 ++++++++++++++++++++++++-
 install/ui/test/data/ipa_init.json             |   3 +-
 ipaserver/plugins/internal.py                  |   1 +
 4 files changed, 247 insertions(+), 4 deletions(-)

diff --git a/install/ui/src/freeipa/navigation/menu_spec.js b/install/ui/src/freeipa/navigation/menu_spec.js
index fb64ccaea56cabdb6addb28543d3f968a746018b..0afc7daceb725cee5677982c68c09d1666d42885 100644
--- a/install/ui/src/freeipa/navigation/menu_spec.js
+++ b/install/ui/src/freeipa/navigation/menu_spec.js
@@ -226,6 +226,11 @@ var nav = {};
                             hidden: true
                         },
                         {
+                            entity: 'location',
+                            facet: 'search',
+                            hidden: true
+                        },
+                        {
                             facet: 'topology-graph',
                             hidden: true
                         }
diff --git a/install/ui/src/freeipa/topology.js b/install/ui/src/freeipa/topology.js
index c26dc685328904ed893c960b6b4b0981cd9d28ce..6736e8998afc49e64b2460a0fbb344be85d50363 100644
--- a/install/ui/src/freeipa/topology.js
+++ b/install/ui/src/freeipa/topology.js
@@ -51,7 +51,8 @@ var topology = IPA.topology = {
             suffix_search: 'topologysuffix_search',
             server_search: 'server_search',
             domainlevel: 'domainlevel_details',
-            topologygraph: 'topology-graph'
+            topologygraph: 'topology-graph',
+            location_search: 'location_search'
         }
     }
 };
@@ -193,6 +194,14 @@ return {
 var make_server_spec = function() {
 return {
     name: 'server',
+    policies: [
+        {
+            $factory: IPA.facet_update_policy,
+            source_facet: 'details',
+            dest_entity: 'location',
+            dest_facet: 'details'
+        }
+    ],
     facets: [
            {
             $type: 'search',
@@ -212,7 +221,6 @@ return {
         },
         {
             $type: 'details',
-            no_update: true,
             disable_facet_tabs: true,
             sections: [
                 {
@@ -221,7 +229,15 @@ return {
                         { name: 'cn', read_only: true },
                         { name: 'ipamindomainlevel', read_only: true },
                         { name: 'ipamaxdomainlevel', read_only: true },
-                        { $type: 'multivalued', name: 'iparepltopomanagedsuffix_topologysuffix', read_only: true }
+                        { $type: 'multivalued', name: 'iparepltopomanagedsuffix_topologysuffix', read_only: true },
+                        {
+                            $type: 'entity_select',
+                            name: 'ipalocation_location',
+                            other_entity: 'location',
+                            other_field: 'idnsname',
+                            flags: ['w_if_no_aci']
+                        },
+                        { name: 'ipalocationweight' }
                     ]
                 }
             ]
@@ -272,6 +288,222 @@ topology.domainlevel_adapter = declare([mod_field.Adapter], {
 });
 
 
+var make_location_spec = function() {
+return {
+    name: 'location',
+    policies: [
+        {
+            $factory: IPA.facet_update_policy,
+            source_facet: 'details',
+            dest_entity: 'server',
+            dest_facet: 'details'
+        },
+        {
+            $factory: IPA.facet_update_policy,
+            source_facet: 'details',
+            dest_entity: 'location',
+            dest_facet: 'search'
+        }
+    ],
+    facets: [
+        {
+            $type: 'search',
+            disable_facet_tabs: false,
+            tabs_in_sidebar: true,
+            tab_label: '@mo:location.label',
+            facet_groups: [topology.search_facet_group],
+            facet_group: 'search',
+            columns: [
+                'idnsname',
+                'description'
+            ]
+        },
+        {
+            $type: 'details',
+            section_layout_class: 'col-sm-12',
+            sections: [
+                {
+                    name: 'information',
+                    label: '@i18n:objects.topology.information',
+                    fields: [
+                        'idnsname',
+                        'description'
+                    ]
+                },
+                {
+                    name: 'servers',
+                    label: '@mo:server.label',
+                    fields: [
+                        {
+                            $factory: topology.location_association_table_widget,
+                            $type: 'association_table',
+                            adapter: topology.location_adapter,
+                            other_entity: 'server',
+                            footer: false,
+                            name: 'cn',
+                            columns: [
+                                {
+                                    name: 'cn',
+                                    link: true
+                                },
+                                {
+                                    name: 'ipalocationweight'
+                                },
+                                {
+                                    name: 'location_relative_weight'
+                                }
+                            ]
+                        }
+                    ]
+                }
+            ]
+        }
+    ],
+    adder_dialog: {
+        fields: [
+            {
+                $type: 'text',
+                name: 'idnsname',
+                required: true
+            },
+            'description'
+        ]
+    }
+};};
+
+topology.location_adapter = declare([mod_field.Adapter], {
+    load: function(data) {
+        var result = this.get_record(data);
+        if (result.servers_server === undefined) return [];
+
+        result = result.servers_server;
+
+        this.result_name = 'servers';
+        var servers = this.get_record(data);
+        this.result_name = 'result';
+
+        var output = [];
+
+        for (var i=0, l=result.length; i<l; i++) {
+            output.push(servers[result[i]]);
+        }
+
+        return output;
+    }
+});
+
+topology.location_server_adder_dialog = function(spec) {
+    spec = spec || {};
+
+    var that = IPA.entity_adder_dialog(spec);
+
+    that.init = function() {
+        that.added.attach(function() {
+            that.facet.refresh();
+            that.facet.on_update.notify();
+        });
+    };
+
+    that.create_add_command = function(record) {
+        var pkey = that.facet.get_pkey();
+        var command = that.entity_adder_dialog_create_add_command(record);
+
+        command.set_option('ipalocation_location', pkey);
+
+        return command;
+    };
+
+    that.init();
+
+    return that;
+};
+
+topology.location_association_table_widget = function(spec) {
+
+    spec = spec || {};
+    spec.name = spec.name || 'servers';
+
+    var that = IPA.association_table_widget(spec);
+
+    that.create_add_dialog = function() {
+
+        var entity_label = that.entity.metadata.label_singular;
+        var pkey = that.facet.get_pkey();
+        var other_entity_label = that.other_entity.metadata.label_singular;
+
+        var title = that.add_title;
+        title = title.replace('${entity}', entity_label);
+        title = title.replace('${primary_key}', pkey);
+        title = title.replace('${other_entity}', other_entity_label);
+
+        return topology.location_server_adder_dialog({
+            title: title,
+            entity: that.other_entity.name,
+            method: 'mod',
+            options: {
+                'ipalocation_location': pkey
+            },
+            sections: [
+                {
+                    fields: [
+                        {
+                            $type: 'entity_select',
+                            name: 'cn',
+                            required: true,
+                            other_entity: that.other_entity.name,
+                            other_field: 'cn',
+                            filter_options: {
+                                'not_in_location': pkey
+                            }
+                        },
+                        {
+                            $type: 'text',
+                            name: 'ipalocationweight'
+                        }
+                    ]
+                }
+            ]
+        });
+    };
+
+
+    that.remove = function(values, on_success, on_error) {
+
+        var pkey = '';
+
+        var batch = rpc.batch_command({
+            on_success: function(data) {
+                that.refresh();
+
+                var count = data.result.count;
+                var msg = text.get('@i18n:association.removed').replace('${count}', count);
+                IPA.notify_success(msg);
+            },
+            on_error: on_error
+        });
+
+        var command, value;
+        for(var i = 0, l=values.length; i<l; i++) {
+            value = values[i];
+
+            command = rpc.command({
+                entity: that.other_entity.name,
+                method: 'mod',
+                args: [value],
+                options: {
+                    'ipalocation_location': pkey
+                }
+            });
+
+            batch.add_command(command);
+        }
+
+        batch.execute();
+    };
+
+    return that;
+};
+
 topology.domainlevel_metadata = function(spec, context) {
     var metadata = metadata_provider.source;
     metadata.objects.domainlevel = {
@@ -970,6 +1202,7 @@ topology.server_spec = make_server_spec();
  */
 topology.domainlevel_spec = make_domainlevel_spec();
 
+topology.location_spec = make_location_spec();
 
 /**
  * Register entity
@@ -985,17 +1218,20 @@ topology.register = function() {
     e.register({type: 'topologysegment', spec: topology.segment_spec});
     e.register({type: 'server', spec: topology.server_spec});
     e.register({type: 'domainlevel', spec: topology.domainlevel_spec});
+    e.register({type: 'location', spec: topology.location_spec});
 
     a.register('domainlevel_set', topology.domainlevel_set_action);
     a.register('segment_add', topology.add_segment_action);
     a.register('segment_del', topology.del_segment_action);
 
     w.register('topology-graph', topology.TopologyGraphWidget);
+    w.register('location_association_table', topology.location_association_table_widget);
     fa.register({
         type: 'topology-graph',
         ctor: topology.TopologyGraphFacet,
         spec: topology.topology_graph_facet_spec
     });
+
 };
 
 phases.on('registration', topology.register);
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 6fbf4c06de99f7b5e2b96eb0a1dbf59583d1e75f..bbee99c9f530032c1459080c7673e0bcaee1cee7 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -585,7 +585,8 @@
                         "topology": {
                             "segment_details": "Segment details",
                             "replication_config": "Replication configuration",
-                            "insufficient_domain_level" : "Managed topology requires minimal domain level ${domainlevel}"
+                            "insufficient_domain_level" : "Managed topology requires minimal domain level ${domainlevel}",
+                            "information": "Information"
                         },
                         "trust": {
                             "account": "Account",
diff --git a/ipaserver/plugins/internal.py b/ipaserver/plugins/internal.py
index 850156c34c47fa3d1fec5facbe06e1889b014552..6b3c712e419f53940a5e2548f10bb8142dac908e 100644
--- a/ipaserver/plugins/internal.py
+++ b/ipaserver/plugins/internal.py
@@ -725,6 +725,7 @@ class i18n_messages(Command):
                 "segment_details": _("Segment details"),
                 "replication_config": _("Replication configuration"),
                 "insufficient_domain_level" : _("Managed topology requires minimal domain level ${domainlevel}"),
+                "information": _("Information"),
             },
             "trust": {
                 "account": _("Account"),
-- 
2.5.5

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to