Skip to content

New sample ng-flow with nodejs #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions samples/nodejs/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "public/bower_components"
}
22 changes: 22 additions & 0 deletions samples/nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# phpstorm project files
.idea/*

# netbeans project files
nbproject

# zend studio for eclipse project files
.buildpath
.project
.settings

# windows thumbnail cache
Thumbs.db

# build
/build/*

# node
/node_modules/*

# bower
/public/bower_components/*
36 changes: 36 additions & 0 deletions samples/nodejs/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var express = require('express')
, app = express()
, bodyParser = require('body-parser')
, server = require('http').Server(app)
, multer = require('multer')
, storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'temp/')
},
filename: function (req, file, cb) {
cb(null, req.body.flowIdentifier);
}
})
, multerUpload = multer({ storage: storage })
, uploadFile = multerUpload.single('file');

app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
next();
});

app.get('/', function(req, res) {
res.sendFile('index.html');
});

app.post('/upload', uploadFile, function(req, res) {
res.status(200).send();
});

server.listen(process.env.PORT || 3000, function(){
console.log('running sample');
});
21 changes: 21 additions & 0 deletions samples/nodejs/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "ng-flow-sample",
"version": "0.0.1",
"ignore": [
"**/.*",
"test",
"samples",
"build",
"*.md",
"karma.conf.js",
"LICENSE",
"Gruntfile.js",
"package.json",
"bower.json"
],
"dependencies": {
"angular": "~1",
"flow.js": "~2",
"ng-flow": "~2"
}
}
15 changes: 15 additions & 0 deletions samples/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "ng-flow-sample",
"author": "Emerson Jose <emersonjprogramador@gmail.com>",
"description":"sample ng-flow with nodejs",
"version": "0.0.1",
"scripts": {
"start": "node app.js"
},
"license": "MIT",
"dependencies": {
"body-parser": "~1.0.0",
"express": "~4.9.8",
"multer": "*"
}
}
50 changes: 50 additions & 0 deletions samples/nodejs/public/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

.drop {
padding: 15px;
border: 2px #f1f1f1 dashed;
border-radius: 5px;
line-height: 34px;
}
.drop.drag-over {
background: #5CB85C;
color: #fff
}
.transfer-box {
margin-bottom: 5px;
}
.transfer-box .progress {
margin-bottom: 0;
}

.thumbnail {
line-height: 20px;
margin-bottom: 5px;
overflow: hidden;
word-break: normal;
}
.thumbnail img {
max-width: 200px;
max-height: 150px;
}

.gallery-box {
width: 200px;
padding: 5px;
margin: 7px;
float: left;
min-height: 200px;
border: 1px solid #ddd;
overflow: hidden;
}
.gallery-box .progress {
margin-bottom: 0;
}
.gallery-box .thumbnail {
height: 188px;
width: 188px;
}
.gallery-box .title {
height: 22px;
overflow: hidden;
display: block;
}
58 changes: 58 additions & 0 deletions samples/nodejs/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

<!DOCTYPE html>
<html ng-app="ng-flow-sample" flow-init>
<head>
<meta charset="UTF-8">
<title>ng-flow sample</title>

<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet"/>
<link href="css/main.css" rel="stylesheet"/>

<script src="bower_components/angular/angular.js" type="text/javascript"></script>
<script src="bower_components/ng-flow/dist/ng-flow-standalone.js" type="text/javascript"></script>
<script src="scripts/app.js" type="text/javascript"></script>

</head>
<body flow-prevent-drop flow-drag-enter="dropClass='drag-over'" flow-drag-leave="dropClass=''">
<div class="container">
<h1>flow nodejs example</h1>

<form enctype="multipart/form-data" name="uploadFile">
<div class="box-body">
<div class="row">
<div flow-object="uploader.flow" flow-files-submitted="$flow.upload()" flow-file-added="!!{png:1,gif:1,jpg:1,jpeg:1}[$file.getExtension()]">
<div class="drop" flow-drop ng-class="dropClass">
<span class="btn btn-default" flow-btn>Upload file</span>
<span class="btn btn-default" flow-btn flow-directory ng-show="$flow.supportDirectory">Upload folder</span>
<b>OR</b>
Drag And Drop your file here
</div>
<br/>
<div>
<div ng-repeat="file in $flow.files" class="gallery-box">
<span class="title">{{file.name}}</span>
<div class="thumbnail" ng-show="$flow.files.length">
<img flow-img="file" />
</div>
<div class="progress progress-striped" ng-class="{active: file.isUploading()}">
<div class="progress-bar" role="progressbar"
aria-valuenow="{{file.progress() * 100}}"
aria-valuemin="0"
aria-valuemax="100"
ng-style="{width: (file.progress() * 100) + '%'}">
<span class="sr-only">{{file.progress()}}% Complete</span>
</div>
</div>
<div class="btn-group">
<a class="btn btn-xs btn-danger" ng-click="file.cancel()">remove</a>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</form>
</div>
</body>
</html>
26 changes: 26 additions & 0 deletions samples/nodejs/public/scripts/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var app = angular.module('ng-flow-sample', ['flow']);

app.config(['flowFactoryProvider', function (flowFactoryProvider) {
flowFactoryProvider.defaults = {
target: 'http://localhost:3000/upload',
permanentErrors: [404, 500, 501],
chunkRetryInterval: 5000,
simultaneousUploads: 4,
testChunks: false,
generateUniqueIdentifier: function(file) {
var getFileExt = function(fileName) {
var fileExt = fileName.split(".");

if ( fileExt.length === 1 || ( fileExt[0] === "" && fileExt.length === 2 )) {
return "";
}

return fileExt.pop();
};

return Date.now() + '.'+ getFileExt(file.name);
}
};
}]);
Binary file added samples/nodejs/temp/flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.