Created
July 31, 2018 23:02
-
-
Save How-Bout-No/4e4e60fecf73ba084b408a2c89d050f7 to your computer and use it in GitHub Desktop.
Auto package-lister script for Reposi3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Auto package-lister script by How-Bout-No | |
// Takes in all packages listed by the 'Packages' file. | |
// This file is specifically set up for my Bootstrap setup, however can be converted to the default setup by changing class names... | |
// and changing the Bootstrap cards to panels. | |
console.log("Listing packages..."); | |
function addRow(dict) { | |
var packname = dict["Name"]; | |
var packver = dict["Version"]; | |
var packdesc = dict["Description"]; | |
var packdepic = dict["Depiction"]; | |
var div = document.createElement('div'); | |
div.className = 'card border-primary mb-3'; | |
div.style = 'margin: 0 auto;max-width: 50rem;' | |
div.innerHTML = | |
'<div class="card-header">'+packname+' <span class="badge badge-primary">'+packver+'</span></div>\ | |
<div class="card-body">\ | |
<h5 class="card-title">'+packdesc+'</h5>\ | |
<a href="'+packdepic+'" class="btn btn-info progress-bar-striped progress-bar-animated grow">More info</a>\ | |
</div>'; | |
document.getElementsByClassName('bs-component')[0].appendChild(div); | |
} | |
$( document ).ready(function() { | |
$.ajax({ | |
type : "GET", | |
dataType: "text", | |
url : ("/Packages"), | |
success: function(data) { | |
var i, j, text, sortpackage; | |
var newdata = data.split('\n\n'); | |
var allpackages = []; | |
for (i = 0; i < newdata.length; i++) { | |
text = newdata[i].replace(/: /g, '\n').split('\n'); | |
sortpackage = {}; | |
for (j= 0; j < text.length; j+=2) { | |
sortpackage[text[j]] = text[j+1]; | |
} | |
allpackages.push(sortpackage); | |
} | |
for (i = 0; i < allpackages.length; i++) { | |
addRow(allpackages[i]); | |
} | |
} | |
}); //ajax | |
}); // ready |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment