Make yum download instructions more dyanamic
authorMagnus Hagander <magnus@hagander.net>
Thu, 8 Jun 2017 11:05:35 +0000 (13:05 +0200)
committerMagnus Hagander <magnus@hagander.net>
Thu, 8 Jun 2017 11:06:39 +0000 (13:06 +0200)
Using the crawled data, propulate dropdown boxes with versions and
platforms, to be able to show simpler instructions of exactly which
commands to use to install using the yum repository.

pgweb/downloads/views.py
pgweb/urls.py
templates/downloads/js/yum.js [new file with mode: 0644]
templates/pages/download/linux/redhat.html

index 63d69981e252a9b7aa6208f61d4ed194d9a5d4fd..0ca19714cf37201c90f16cdb79a5fb5e789a7fad 100644 (file)
@@ -192,6 +192,13 @@ def mirrorselect(request, path):
        return HttpResponseRedirect("https://ftp.postgresql.org/pub/%s" % path)
 
 
+# Render javascript for yum downloads
+def yum_js(request):
+       with open(settings.YUM_JSON) as f:
+               jsonstr = f.read()
+       return render_to_response('downloads/js/yum.js', {
+               'json': jsonstr,
+               }, content_type='application/json')
 
 #######
 # Product catalogue
index a8b18df1b3d7df423f56eb62ede4638a8e198881..d669f1322236598a68f4754dbf3c5695506aa8a3 100644 (file)
@@ -36,6 +36,7 @@ urlpatterns = patterns('',
        (r'^applications-v2.xml$', 'pgweb.downloads.views.applications_v2_xml'),
        (r'^download/uploadftp/', 'pgweb.downloads.views.uploadftp'),
        (r'^download/uploadyum/', 'pgweb.downloads.views.uploadyum'),
+       (r'^download/js/yum.js', 'pgweb.downloads.views.yum_js'),
 
        (r'^docs/$', 'pgweb.docs.views.root'),
        (r'^docs/manuals/$', 'pgweb.docs.views.manuals'),
diff --git a/templates/downloads/js/yum.js b/templates/downloads/js/yum.js
new file mode 100644 (file)
index 0000000..1a34f55
--- /dev/null
@@ -0,0 +1,95 @@
+var repodata = {{json|safe}};
+
+window.onload = function() {
+   versions = Object.keys(repodata['reporpms']).sort().reverse();
+   for (var p in versions) {
+      var opt = document.createElement('option');
+      opt.text = versions[p];
+      document.getElementById('version').add(opt);
+   }
+
+   verChanged();
+}
+
+function verChanged() {
+   var newver = document.getElementById('version').value;
+   var platbox = document.getElementById('platform');
+
+   while (platbox.options.length > 0) {
+      platbox.options.remove(0);
+   }
+   var opt = document.createElement('option');
+   opt.text = '* Select your platform';
+   opt.value = -1;
+   platbox.add(opt);
+
+   plats = Object.keys(repodata['reporpms'][newver]).sort(
+       function(a,b) {
+          return repodata['platforms'][a].s - repodata['platforms'][b].s;
+       }
+   );
+   for (p in plats) {
+      var opt = document.createElement('option');
+      opt.text = repodata['platforms'][plats[p]].t;
+      opt.value = plats[p];
+      platbox.add(opt);
+   }
+
+   platChanged();
+}
+
+function platChanged() {
+   var ver = document.getElementById('version').value;
+   var plat = document.getElementById('platform').value;
+   var archbox = document.getElementById('arch');
+
+   while (archbox.options.length > 0) {
+      archbox.options.remove(0);
+   }
+
+   if (plat == -1) {
+      archChanged();
+      return;
+   }
+
+   var platname = repodata['platforms'][plat].t;
+
+   archs = Object.keys(repodata['reporpms'][ver][plat]).sort().reverse();
+   for (a in archs) {
+      var opt = document.createElement('option');
+      opt.text = archs[a];
+      opt.value = archs[a];
+      archbox.add(opt);
+   }
+
+   archChanged();
+}
+
+function archChanged() {
+   var ver = document.getElementById('version').value;
+   var plat = document.getElementById('platform').value;
+   var arch = document.getElementById('arch').value;
+
+   if (plat == -1) {
+      document.getElementById('reporpm').innerHTML = 'Select version and platform above';
+      document.getElementById('clientpackage').innerHTML = 'Select version and platform above';
+      document.getElementById('serverpackage').innerHTML = 'Select version and platform above';
+      document.getElementById('initdb').innerHTML = 'Select version and platform above';
+      return;
+   }
+
+   var pinfo = repodata['platforms'][plat];
+   var shortver = ver.replace('.', '');
+
+   var url = 'https://download.postgresql.org/pub/repos/yum/' + ver + '/' + pinfo['p'] + '-' + arch + '/pgdg-' + pinfo['f'] + shortver + '-' + ver + '-' + repodata['reporpms'][ver][plat][arch] + '.noarch.rpm';
+
+   document.getElementById('reporpm').innerHTML = pinfo['i'] + ' install ' + url;
+   document.getElementById('clientpackage').innerHTML = pinfo['i'] + ' install postgresql' + shortver;
+   document.getElementById('serverpackage').innerHTML = pinfo['i'] + ' install postgresql' + shortver + '-server';
+   if (pinfo.d) {
+       document.getElementById('initdb').innerHTML = '/usr/pgsql-' + ver + '/bin/postgresql' + shortver + '-setup initdb<br/>systemctl enable postgresql-' + ver + '<br/>systemctl start postgresql-' + ver;
+   }
+   else {
+       document.getElementById('initdb').innerHTML = 'service postgresql-' + ver + ' initdb<br/>chkconfig postgresql-' + ver + ' on<br/>service postgresql-' + ver + ' start';
+   }
+}
index 31141aa7828e4a1f36abd0caf1f5b3569754a127..c2940550e729b21654f9c6d80087f261c5c586cc 100644 (file)
@@ -1,5 +1,8 @@
 {%extends "base/page.html"%}
 {%block title%}Linux downloads (Red Hat family){%endblock%}
+{%block extrahead%}
+<script language="javascript" src="/download/js/yum.js?{{gitrev}}"></script>
+{%endblock%}
 {%block contents%}
 
 <h1>Linux downloads (Red Hat family)</h1>
@@ -16,8 +19,7 @@ supported versions for the most common distributions.
 
 <a name="yum"></a><h2>PostgreSQL Yum Repository</h2>
 <p>
-If the version supplied by your operating system is not the one you want,
-you can use the PostgreSQL Yum Repository. This repository will integrate
+This repository will integrate
 with your normal systems and patch management, and provide automatic
 updates for all supported versions of PostgreSQL throughout the support
 <a href="/support/versioning/">lifetime</a> of PostgreSQL.
@@ -30,58 +32,26 @@ on Fedora, all versions are not available on this platform, and we recommend not
 using Fedora for server deployments.
 </p>
 <p>
-To use the yum repository, you must first install the <i>repository RPM</i>.
-To do this, download the correct RPM from the
-<a href="https://yum.postgresql.org/repopackages.php">repository RPM listing</a>,
-and install it with commands like:
-</p>
-<p>
-On RHEL and its derivatives:
-<code>
-yum install https://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm
-</code>
-</p>
-<p>
-On Fedora,
-<code>
-dnf install https://download.postgresql.org/pub/repos/yum/9.6/fedora/fedora-25-x86_64/pgdg-fedora96-9.6-3.noarch.rpm
-</code>
-</p>
-<p>
-Once this is done, you can proceed to install and update packages the
-same way as the ones included in the distribution.
-</p>
-<p>
-For RHEL and its derivatives:
-<code>
-yum install postgresql96-server postgresql96-contrib<br/>
-(or yum groupinstall "PostgreSQL Database Server 9.6 PGDG")<br/>
-service postgresql-9.6 initdb<br/>
-chkconfig postgresql-9.6 on
-service postgresql-9.6 start
-</code>
-or, on Fedora 24 and other later derived distributions:<br />
-<code>
-dnf install postgresql96-server postgresql96-contrib<br/>
-(or dnf groupinstall "PostgreSQL Database Server 9.6 PGDG")<br/>
-/usr/pgsql-9.6/bin/postgresql96-setup initdb<br/>
-systemctl enable postgresql-9.6.service<br/>
-systemctl start postgresql-9.6.service
-</code>
-</p>
-<p>
-Package names in the
-PostgreSQL yum repository follows the same standard as the ones included
-in the main repositories, but include the version number, such as:
+To use the yum repository, follow these steps:
 </p>
 <ul>
- <li>postgresql96</li>
- <li>postgresql96-server</li>
- <li>postgresql96-contrib</li>
- <li>pgadmin3_96</li>
+  <li>Select version: <select id="version" onChange="verChanged()"></select><br/></li>
+  <li>Select platform: <select id="platform" onChange="platChanged()"></select></li>
+  <li>Select architecture: <select id="arch" onChange="archChanged()"></select></li>
+  <li>Install the repository RPM:
+    <code id="reporpm"></code>
+  </li>
+  <li>Install the client packages:
+    <code id="clientpackage"></code>
+  </li>
+  <li>Optionally install the server packages:
+    <code id="serverpackage"></code>
+  </li>
+  <li>Optionally initialize the database and enable automatic start:
+    <code id="initdb"></code>
+  </li>
 </ul>
 
-
 <h2>Included in distribution</h2>
 <p>
 These distributions all include PostgreSQL by default. To install