Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gulp/tasks/appStoreProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ function _next(req,res,targetUrl,vid){
proxy.web(req, res, { target: targetUrl });
}

gulp.task('runAppStore', ['startAppStoreProxy','reinstall-primo-node-modules','custom-js','custom-scss','custom-css']); //watch
gulp.task('runAppStore', ['reinstall-primo-node-modules','custom-js','custom-scss','custom-css']); //watch

gulp.task('web', ['serve']); //watch
gulp.task('web', ['serve']); //watch
120 changes: 119 additions & 1 deletion gulp/tasks/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ const npmi= require('npmi');
const rename= require('gulp-rename');
const buildCustomJs= require('./buildCustomJs');
const storage = require('node-persist');
const httpProxy= require('http-proxy');
const http = require('http');
const primoProxy = require('../primoProxy');
const config = require('../config');
const _url = require("url");


let proxy = httpProxy.createProxyServer({});
gulp.task('serve', ['bundle-js', 'watch-app'], function() {
let appName = 'primo-explore';
//1. serve with default settings
/* var server = gls.static(); //equals to gls.static('public', 3000);
server.start();*/
Expand Down Expand Up @@ -252,12 +260,122 @@ gulp.task('serve', ['bundle-js', 'watch-app'], function() {
});

})

appS.all('*',function(req, res, next){
let cookies = utils.parseCookies(req);
let urlForProxy = cookies['urlForProxy'];
let viewForProxy = cookies['viewForProxy'];
let confPath = config.getVe() ? '/primaws/rest/pub/configuration' : '/primo_library/libweb/webservices/rest/v1/configuration';
let confAsJsPath = '/primo-explore/config_';

let fixConfiguration = function (res, res1, isConfByFile) {
let dirForProxy = utils.getUserId(req);
let body = '';

res1.setEncoding('utf8');

res1.on("data", function (chunk) {
body = body + chunk;
});

res1.on("end", function () {

let vid = dirForProxy || config.view() || '';
let customizationProxy = primoProxy.getCustimazationObject(vid, appName);


if (isConfByFile) {
res.end('');

} else {

let jsonBody = JSON.parse(body);
let newBodyObject = jsonBody;

newBodyObject.customization = customizationProxy;
let newBody = JSON.stringify(newBodyObject);

res.body = newBody;

/*console.log('newBody: ' +newBody);*/
res.end(newBody);
}

});
};
if (req.url.startsWith(confAsJsPath) || req.url.startsWith(confPath)) {
let isConfByFile = false;
if (req.url.startsWith(confAsJsPath)) {
isConfByFile = true;
}
let proxyUrl = urlForProxy || config.PROXY_SERVER;
let base = proxyUrl.replace('http:\/\/', '').replace('https:\/\/', '');
let method = proxyUrl.split('://')[0];
let parts = base.split(':');
let hostname = parts[0];
let port = parts[1];


let options = {
hostname: hostname,
port: port,
path: req.url,
method: 'GET',
headers: {
'X-From-ExL-API-Gateway': '1'
}
};
let requestObject = http;
if (method === 'https') {
requestObject = https;
}
let req2 = requestObject.request(options, (res1) => {
fixConfiguration(res, res1, isConfByFile);
});

req2.on('error', (e) => {
_next(req, res, urlForProxy, viewForProxy);
});

req2.write('');
req2.end();

}
else {
_next(req, res, urlForProxy, viewForProxy);
}
})
appS.listen(8004, function () {
console.log('Example app listening on port 8004!')
})
/*server.start();*/
function _next(req,res,targetUrl,vid){


console.log('vid=' + vid);
console.log('url=' + targetUrl);
let path = _url.parse(req.url).pathname;


let proxyUrl = targetUrl || config.PROXY_SERVER;
let fixedurl = proxyUrl+req.url;
let base = proxyUrl.replace('http:\/\/','').replace('https:\/\/','');
let method = proxyUrl.split('://')[0];
let parts = base.split(':');
let hostname = parts[0];
let port = parts[1];

console.log('this is the current path: ' + path);
if(path.indexOf('/primo-explore/custom') > -1) {
console.log('req url=' + _url.parse(req.url));
let filePath= process.cwd() + path;
console.log(filePath);
let filestream= fs.createReadStream(filePath);
filestream.pipe(res);
return;
}

proxy.web(req, res, { target: targetUrl });
}

/* server.get('/app', function (req, res) {
console.log('22222');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"gulp-template": "4.0.0",
"gulp-wrap": "0.11.0",
"gulp-zip": "3.1.0",
"html2canvas": "^1.0.0-alpha.10",
"http-response-object": "1.1.0",
"listdirs": "3.0.0",
"lodash": "4.16.4",
Expand Down
6 changes: 6 additions & 0 deletions primo-explore/www/html2canvas.min.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion primo-explore/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
<link rel="stylesheet" href="css/angular-material.css"></link>
<link rel="stylesheet" href="css/main.css"></link>
<script type="text/javascript" src="bundle.js"></script>
<script type="text/javascript" src="html2canvas.min.js"></script>


<style>
.listdemoBasicUsage md-divider {
margin-top: 10px;
margin-bottom: 0; }
</style>

</head>

<body ng-app="devenv">




<server></server>
</body>
</html>
7 changes: 7 additions & 0 deletions primo-explore/www/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const ngCookies= require('angular-cookies');




let app = angular.module('devenv', [material_module, ngCookies])
app.config(['$locationProvider', function($locationProvider){
$locationProvider.html5Mode({
Expand Down Expand Up @@ -34,6 +35,9 @@ app.component(featuresList.name, featuresList.config);
const downloadPackage= require('./downloadPackage/downloadPackage.directive');
app.component(downloadPackage.name, downloadPackage.config);

const share= require('./share/share.directive');
app.component(share.name, share.config);


/*-----------------services------------ */
const iframeService= require('./utils/iframe.service');
Expand All @@ -47,3 +51,6 @@ app.service(featuesService.name, featuesService.service);

const fileUploaderService = require('./utils/fileUploader.service');
app.service(fileUploaderService.name, fileUploaderService.service);

const shareService = require('./utils/share.service');
app.service(shareService.name, shareService.service);
9 changes: 6 additions & 3 deletions primo-explore/www/server.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
</md-tab>
</md-tabs>

<div flex="60" ng-if="$ctrl.isUp()">
<div id="primo-explore-iframe-container" flex="60" ng-if="$ctrl.isUp()">
<md-button href="{{::$ctrl.getIframeUrl()}}" target="_blank">Open in full view</md-button>
<iframe id="primo-explore-iframe" style="min-width:100%;min-height:100%" ng-if="$ctrl.isUp()" src="{{::$ctrl.getIframeUrl()}}"></iframe>
<md-button ng-click="$ctrl.restart()" ng-if="$ctrl.isUp()">ReStart server(wait 10 seconds after changes)</md-button>
</div>
</md-content>
</div>
<div>
<prm-share></prm-share>
</div>


</md-content>
</div>
32 changes: 32 additions & 0 deletions primo-explore/www/share/share.directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Created by shoulm on 15/02/2018.
*/

class PrmShare{
constructor(shareService){
this.shareService = shareService;
this.options = {
filename: 'target1.png',
downloadText: 'Download me',
cancelText: 'Close it!'
}
}


createImage(){
this.shareService.createCanvas().then((response)=>{
console.log('canvas created');
}, (err)=>{
console.log('failed to create canvas: '+ err)
});
}
}
PrmShare.$inject=['shareService'];

module.exports = {
name: 'prmShare',
config: {
controller: PrmShare,
templateUrl: '/share/share.html'
}
}
2 changes: 2 additions & 0 deletions primo-explore/www/share/share.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<button ng-click="$ctrl.createImage()">Take A screen Shot</button>
<canvas id="canvas"></canvas>
4 changes: 1 addition & 3 deletions primo-explore/www/utils/iframe.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class IframeService{
}

getIframeUrl(){
return this.$sce.trustAsResourceUrl(this.$location.protocol() + '://' + this.$location.host() + ':8003/primo-explore/search/?vid='+this.config.view+'&dirName='+this.config.dirName+'&url='+this.config.url);
return this.$sce.trustAsResourceUrl(this.$location.protocol() + '://' + this.$location.host() + ':8004/primo-explore/search/?vid='+this.config.view+'&dirName='+this.config.dirName+'&url='+this.config.url);
}
isUp(){
return this._up;
Expand All @@ -46,5 +46,3 @@ module.exports = {
name: 'iframeService',
service: IframeService
}


21 changes: 21 additions & 0 deletions primo-explore/www/utils/share.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Created by shoulm on 06/02/2018.
*/
class ShareService{
constructor(){
}
createCanvas(){
html2canvas(document.querySelector("#primo-explore-iframe-container")).then(function(canvas) {
document.body.appendChild(canvas);

});
}

}
ShareService.$inject= [];


module.exports = {
name: 'shareService',
service: ShareService
}