Skip to content

Commit

Permalink
Add RequireJS to manage dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mok committed Sep 3, 2018
1 parent 69174e9 commit a78f073
Show file tree
Hide file tree
Showing 25 changed files with 16,857 additions and 347 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
11 changes: 5 additions & 6 deletions certificate.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<html>
<head>
<title>Create Certificate</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' rel='stylesheet' type='text/css'/>
<link rel="shortcut icon" type="image/png" href="images/certificate.ico"/>
<link href="css/fonts.css" rel="stylesheet" type="text/css"/>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" type="image/png" href="images/certificate.ico"/>
<script type="text/javascript" data-main="js/certificate" src="js/lib/require-2.3.6.min.js"></script>
<script type="text/javascript" src="js/lib/require-config.js"></script>
</head>
<body class="container">
<div class="page-header">
Expand Down Expand Up @@ -32,7 +34,4 @@ <h1>Create Certificate</h1>
<a href="issuer-certificates.html" class="btn">Back</a>
</form>
</body>
<script src="https://cdn.rawgit.com/ethereum/web3.js/develop/dist/web3.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="js/certificate.js"></script>
</html>
6 changes: 6 additions & 0 deletions css/bootstrap.min.css

Large diffs are not rendered by default.

112 changes: 112 additions & 0 deletions css/fonts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* cyrillic-ext */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFWJ0bbck.woff2) format('woff2');
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* cyrillic */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFUZ0bbck.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* greek-ext */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFWZ0bbck.woff2) format('woff2');
unicode-range: U+1F00-1FFF;
}
/* greek */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFVp0bbck.woff2) format('woff2');
unicode-range: U+0370-03FF;
}
/* vietnamese */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFWp0bbck.woff2) format('woff2');
unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFW50bbck.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(https://fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFVZ0b.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* cyrillic-ext */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 700;
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN7rgOX-hpOqc.woff2) format('woff2');
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* cyrillic */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 700;
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN7rgOVuhpOqc.woff2) format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* greek-ext */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 700;
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN7rgOXuhpOqc.woff2) format('woff2');
unicode-range: U+1F00-1FFF;
}
/* greek */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 700;
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN7rgOUehpOqc.woff2) format('woff2');
unicode-range: U+0370-03FF;
}
/* vietnamese */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 700;
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN7rgOXehpOqc.woff2) format('woff2');
unicode-range: U+0102-0103, U+0110-0111, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 700;
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN7rgOXOhpOqc.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 700;
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN7rgOUuhp.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
14 changes: 6 additions & 8 deletions issuer-certificates.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Issued Certificates</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet" type="text/css"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" type="image/png" href="images/certificate.ico"/>
<script src="https://cdn.rawgit.com/ethereum/web3.js/develop/dist/web3.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="js/issuer-certificates.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>Issued Certificates</title>
<link href="css/fonts.css" rel="stylesheet" type="text/css"/>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" type="image/png" href="images/certificate.ico"/>
<script type="text/javascript" data-main="js/issuer-certificates" src="js/lib/require-2.3.6.min.js"></script>
<script type="text/javascript" src="js/lib/require-config.js"></script>
</head>
<body class="container">
<div class="page-header">
Expand Down
13 changes: 6 additions & 7 deletions issuer-list.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Issuer Listing</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' rel='stylesheet' type='text/css'/>
<link rel="shortcut icon" type="image/png" href="images/certificate.ico"/>
<title>Issuer Listing</title>
<link href="css/fonts.css" rel="stylesheet" type="text/css"/>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" type="image/png" href="images/certificate.ico"/>
<script type="text/javascript" data-main="js/issuer-list" src="js/lib/require-2.3.6.min.js"></script>
<script type="text/javascript" src="js/lib/require-config.js"></script>
</head>
<body class="container">
<div class="page-header">
Expand All @@ -27,7 +29,4 @@ <h1>Issuer Listing</h1>
<a href="issuer.html" class="btn btn-primary">Create Issuer</a>
<a href="admin.html" class="btn">Back</a>
</body>
<script src="https://cdn.rawgit.com/ethereum/web3.js/develop/dist/web3.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="js/issuer-list.js"></script>
</html>
13 changes: 6 additions & 7 deletions issuer.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Create Issuer</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' rel='stylesheet' type='text/css'/>
<link rel="shortcut icon" type="image/png" href="images/certificate.ico"/>
<title>Create Issuer</title>
<link href="css/fonts.css" rel="stylesheet" type="text/css"/>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" type="image/png" href="images/certificate.ico"/>
<script type="text/javascript" data-main="js/issuer" src="js/lib/require-2.3.6.min.js"></script>
<script type="text/javascript" src="js/lib/require-config.js"></script>
</head>
<body class="container">
<div class="page-header">
Expand Down Expand Up @@ -32,7 +34,4 @@ <h1>Create Issuer</h1>
<a href="issuer-list.html" class="btn">Cancel</a>
</form>
</body>
<script src="https://cdn.rawgit.com/ethereum/web3.js/develop/dist/web3.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="js/issuer.js"></script>
</html>
89 changes: 45 additions & 44 deletions js/certificate.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
$(document).ready(function() {
requireJS.require(['settings', 'web3', 'jquery'], function (settings) {

var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
$(document).ready(function () {

if (web3.isConnected()) {
var web3 = new Web3(new Web3.providers.HttpProvider(settings.provider));

console.log('Web3 successfully connected');
var issuerAccount = web3.eth.accounts[1];
var abiDefinition = [{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"getIssuerName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"getStudentName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getIssuerCertificates","outputs":[{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"listStudentAddresses","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"getIssuerDetails","outputs":[{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"student","type":"address"},{"name":"courseTitle","type":"string"},{"name":"completionDate","type":"string"},{"name":"expiryDate","type":"string"}],"name":"createCertificate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"index","type":"uint256"}],"name":"getCertificateDetails","outputs":[{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"string"},{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"},{"name":"_name","type":"string"},{"name":"_issuerAddress","type":"string"},{"name":"_logoUrl","type":"string"}],"name":"createIssuer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"},{"name":"_name","type":"string"}],"name":"createStudent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"listIssuerAddresses","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getStudentCertificates","outputs":[{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"student","type":"address"},{"name":"issuer","type":"address"},{"name":"courseTitle","type":"string"}],"name":"verifyCertificate","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}];
var contractAddress = '0x64ec4b719fa6b1fb835b7212e1973236be746989';
var masterContract = web3.eth.contract(abiDefinition);
var contractInstance = masterContract.at(contractAddress);
web3.eth.defaultAccount = issuerAccount;
if (web3.isConnected()) {

try {
var issuerName = contractInstance.getIssuerName(issuerAccount);
$('h1').html('Create Certificate - ' + issuerName);
} catch (e) {
console.log(e);
$('.alert-danger').html('Issuer not found.').show();
}
console.log('Web3 successfully connected');
var issuerAccount = web3.eth.accounts[1];
var masterContract = web3.eth.contract(settings.abiDefinition);
var contractInstance = masterContract.at(settings.contractAddress);
web3.eth.defaultAccount = issuerAccount;

try {
var issuerName = contractInstance.getIssuerName(issuerAccount);
$('h1').html('Create Certificate - ' + issuerName);
} catch (e) {
console.log(e);
$('.alert-danger').html('Issuer not found.').show();
}

$('form').submit(function (event) {
$('.alert-danger, .alert-success').hide();
var courseTitle = $("#course-title").val();
var completionDate = $("#completion-date").val();
var expiryDate = $("#expiry-date").val();
var address = $("#address").val();
var index = web3.eth.accounts.indexOf(address);
$('form').submit(function (event) {
$('.alert-danger, .alert-success').hide();
var courseTitle = $("#course-title").val();
var completionDate = $("#completion-date").val();
var expiryDate = $("#expiry-date").val();
var address = $("#address").val();
var index = web3.eth.accounts.indexOf(address);

if (index < 0) {
$('.alert-danger').html('Account address not found.').show();
console.log('Valid addresses', web3.eth.accounts);
} else {
try {
var estimatedGas = contractInstance.createCertificate.estimateGas(address, courseTitle, completionDate, expiryDate);
contractInstance.createCertificate(address, courseTitle, completionDate, expiryDate, {from: issuerAccount, gas: estimatedGas});
$('.alert-success').show();
$('#course-title, #completion-date, #expiry-date, #address').val('');
} catch (e) {
console.log(e);
$('.alert-danger').html('Error occurred.').show();
if (index < 0) {
$('.alert-danger').html('Account address not found.').show();
console.log('Valid addresses', web3.eth.accounts);
} else {
try {
var estimatedGas = contractInstance.createCertificate.estimateGas(address, courseTitle, completionDate, expiryDate);
contractInstance.createCertificate(address, courseTitle, completionDate, expiryDate, {from: issuerAccount, gas: estimatedGas});
$('.alert-success').show();
$('#course-title, #completion-date, #expiry-date, #address').val('');
} catch (e) {
console.log(e);
$('.alert-danger').html('Error occurred.').show();
}
}
}

event.preventDefault();
});
} else {
$('form').prepend('<div class="alert alert-danger">Blockchain not connected</div>');
$(':submit').prop('disabled', true);
}
event.preventDefault();
});
} else {
$('form').prepend('<div class="alert alert-danger">Blockchain not connected</div>');
$(':submit').prop('disabled', true);
}
});
});
Loading

0 comments on commit a78f073

Please sign in to comment.