* client load on startup
* spawn from techrec the ffmpeg' process
* testing
This commit is contained in:
antifaz 2013-11-19 23:16:03 +01:00
parent b786b405d2
commit ffa0f1784d
7 changed files with 145 additions and 73 deletions

View file

@ -17,7 +17,8 @@ a{
max-width:50%;
margin:auto;
background-color:#F6F7BD;
background-image: url("img/7915.png") ;
border:1px solid black;
background-image: url("../img/7915.png") ;
background-repeat:no-repeat;
background-attachment:fixed;
background-position: 2% 35%;
@ -56,6 +57,24 @@ a{
font-weight:bold;
}
.downloadbutton {
max-height:20px;
background-color:red;
}
.searchresult {
margin-top:10px;
border:2px dashed #ccc;
margin:3px;
font-size:0.9em;
padding:3px;
}
.timevalues {
font-size:0.9em;
}
.namevalues {
font-weight:bolder;
}
#addnewrecarea {
width:100%;
text-align:right;

BIN
client/img/button.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
client/img/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -11,12 +11,15 @@
<script type="text/javascript" src="js/reclibrary.js"></script>
<script>
/*
TODO:
prendere lo stato !!!
*/
$(document).ready(function(){
$("#newlink").click( function(){
rec_new();
});
rec_new();
});
</script>
@ -27,13 +30,16 @@ $(document).ready(function(){
<div id="pagecontainer">
<h1> techr*c </h1>
<h1> techr*c </h1>
<h2> <a href="tempo.html"> macchina del tempo</a> </h2>
<h2>
<a href="#" id="newlink">+ nuova registrazione</a> <br />
<a href="tempo.html"> macchina del tempo</a>
</h2>
<div id="buttonscontainer"> </div>
<div id="buttonscontainer"> </div>
<div id="addnewrecarea"> </div>
<div id="addnewrecarea"> </div>
</div>

View file

@ -16,10 +16,40 @@ TODO:
prendere lo stato !!!
*/
$(document).ready(function(){
$("#searchform").submit(
function () {
alert("Submit");
function (event) {
event.preventDefault();
dataString = $(this).serialize();
var request = RecAjax("search", dataString, "dads");
$("#searchresult").html(" ");
request.done( function(data) {
console.log("Ricevuto data", data);
$.each(data, function(key, val) {
console.log("Extract " + key );
var divstring = "<div class=\"searchresult\" id=\""+ rs_trxarea(key) +"\"> </div>";
$("#searchresult").append( divstring );
// var str = newformstr( key ); // new form
var str = "<div class=\"namevalues\">"+val.name+" - <a href=\"\">Scarica</a></div>";
str += "<span class=\"timevalues\">["+val.starttime+" >>> "+val.endtime+"]</span>"
$("#"+rs_trxarea(key)).html(str);
// $("#"+rs_trxname(key)).val( val.name );
// $("#"+rs_inputstart(key)).val( val.starttime );
// $("#"+rs_inputend(key)).val( val.endtime );
if (val.state == "CODA") {}
if (val.state == "RUN") {}
if (val.state == "DONE") {}
});
});
});
$("#searchform").submit();
});
</script>
@ -36,9 +66,10 @@ $(document).ready(function(){
<div id="buttonscontainer">
<form action="#" method="POST" id="searchform">
<input type="text" name="search" />
<input type="text" id="starttime" name="starttime" placeholder="Start: 2014-05-01-44-55-01" />
<input type="text" id="endtime" name="endtime" placeholder="End: 2014-05-01-44-55-01" />
<input type="text" id="name" name="name" placeholder="name" />
<input type="text" id="starttime" name="starttime" placeholder="Start: 2014-05-01-44-55-01" />
<input type="text" id="endtime" name="endtime" placeholder="End: 2014-05-01-44-55-01" />
<input type="submit" value="Cerca" />
</form>
</div>

View file

@ -18,7 +18,7 @@ class RecServer:
def start(self):
self._app.run(host=self._host, port=self._port)
# @hook('after_request')
@hook('after_request')
def enable_cors(self):
#These lines are needed for avoiding the "Access-Control-Allow-Origin" errors
response.headers['Access-Control-Allow-Origin'] = '*'
@ -34,16 +34,15 @@ class RecServer:
self._app.route('/create', method="POST", callback=self.create)
self._app.post('/create', callback=self.create)
self._app.route('/get', method="GET", callback=self.getrec)
self._app.route('/get/', method="GET", callback=self.getrec)
self._app.route('/get/', method="GET", callback=self.getrec)
self._app.route('/get/<recid>', method="GET", callback=self.getrec)
# self._app.route('/get', method="GET", callback=self.getrec)
# self._app.route('/get/', method="GET", callback=self.getrec)
# self._app.route('/get/<recid>', method="GET", callback=self.getrec)
self._app.route('/search', method="GET", callback=self.search)
self._app.route('/search/', method="GET", callback=self.search)
self._app.route('/search/<recid>', method="GET", callback=self.search)
self._app.route('/oldsearch/<key>/<value>', method="GET", callback=self.search)
self._app.route('/search/<args:path>', method="GET", callback=self.search)
self._app.route('/search', method="POST", callback=self.search)
# self._app.route('/search/', method="POST", callback=self.search)
# self._app.route('/search/<recid>', method="POST", callback=self.search)
# self._app.route('/oldsearch/<key>/<value>', method="POST", callback=self.search)
# self._app.route('/search/<args:path>', method="POST", callback=self.search)
self._app.route('/delete/<recid>', method="GET", callback=self.delete)
self._app.route('/delete/<recid>/', method="GET", callback=self.delete)
@ -55,55 +54,78 @@ class RecServer:
# @route('/create', method=['OPTIONS','POST'])
def create(self):
self.enable_cors()
print "ALL ITEM", request.POST.allitems()
req = dict( request.POST.allitems() )
ret = {}
for k,v in request.POST.allitems():
print "P", k, v
ret[k] = v
return ret
"""
a = Rec(name="Mimmo1",starttime="ora",endtime="fine")
db.add( a )
db.printall()
db.search( Rec(name="Mimmo1") )"""
# @route('/get')
# @route('/get/')
# @route('/get/<recid>/')
def getrec(self, recid=None):
if not recid:
print "No ID"
print "REQ", req
if req["starttime-"+req["recid"]] != "":
starttime = datetime.datetime.strptime( req["starttime-"+req["recid"]] , "%Y/%m/%d %H:%M:%S")
else:
print "ID %s id" % ( recid )
starttime = ""
if req["endtime-"+req["recid"]] != "":
endtime = datetime.datetime.strptime( req["endtime-"+req["recid"]] , "%Y/%m/%d %H:%M:%S")
else:
endtime = ""
self.db.add( Rec(name=req["name-"+req["recid"]],
starttime=starttime,
endtime=endtime )
)
return { "msg": "Nuova registrazione aggiunta" }
# @route('/active')
def getactive(self):
print "GetActive"
# @route('/delete/<recid>')
# @route('/delete/<recid>/')
# @route('/delete/<recid>') # @route('/delete/<recid>/')
def delete( self, recid = None ):
if not recid:
self.rec_err("No recid!")
self.rec_err("Delete")
def rec_err(self, msg):
return { "error": msg,}
return { "error": msg }
# @route('/search')
# @route('/search/')
# @route('/search/<key>/<value>')
"""
@route('/search') # @route('/search/') # @route('/search/<key>/<value>')
"""
def search( self, args=None):
if args == None:
print "Cerco tutti"
print args.split("/")
print self.db._search()
return self.rec_err("err")
self.enable_cors()
req = dict( request.POST.allitems() )
name = req["name"]
if req["name"] == "": name = None
starttime = req["starttime"]
if req["starttime"] == "": name = None
endtime = req["endtime"]
if req["endtime"] == "": endtime = None
values = self.db._search(name=name, starttime=starttime, endtime=endtime)
ret = {}
for rec in values:
recid = "rec-" + str(rec.id)
ret [recid] = {}
ret [recid]["name"] = rec.name
ret [recid]["starttime"] = rec.starttime.strftime("%Y-%m-%d-%H-%H-%s")
if rec.endtime != None:
ret [recid]["endtime"] = rec.endtime.strftime("%Y-%m-%d-%H-%H-%s")
else:
rec.endtime = ""
ret [recid]["state"] = rec.state
# print "RET ", ret
"""
print "VALUES ", values
print type(self.rec_err("sdiaso")), " - " , type(values)
print "ERR" , self.rec_err("sdiaso")"""
logging.info("Return: %s" % ret);
return ret
# @route('/favicon.ico')
def favicon(self):
return static_file('icon.ico', root="./img/", mimetype="image/ico")
@ -126,5 +148,5 @@ class RecServer:
TESTs
"""
if __name__ == "__main__":
c = RecServer()
c = RecServer(host="0.0.0.0")
c.start()

View file

@ -24,13 +24,6 @@ records manager (RecDB() class)
Base = declarative_base()
""" ************
RECORD STATE FLAGS
************ """
QUEUE = 0
RUN = 2
DONE = 4
PAGESIZE = 10
@ -39,9 +32,9 @@ class Rec(Base):
__tablename__ = 'rec'
id = Column(Integer, primary_key=True)
name = Column(String)
endtime = Column(DateTime)
starttime = Column(DateTime)
state = Column(Integer)
starttime = Column(DateTime, nullable = True)
endtime = Column(DateTime, nullable = True)
state = Column(String)
def __init__(self, name="", starttime=None, endtime=None, asjson=""):
self.error = 0
@ -65,7 +58,7 @@ class Rec(Base):
self.starttime = asjson[0]['starttime']
selfendtime = asjson[0]['endtime']
self.state = QUEUE
self.state = "CODA"
# launch the job for processing files
@ -84,10 +77,10 @@ class Rec(Base):
return self.error
def set_run(self):
self.state = RUN
self.state = "RUN"
def set_done(self):
self.state = DONE
self.state = "DONE"
def __repr__(self):
return "<Rec('%s','%s','%s', '%s', '%s')>" % (self.id, self.name, self.starttime, self.endtime, self.state)
@ -131,15 +124,16 @@ class RecDB:
def commit(self):
self.session.commit()
def get_all(self,page=0, page_size=PAGESIZE):
def get_all(self, page=0, page_size=PAGESIZE):
return self._search(page=page, page_size=page_size)
def _search(self, _id=None, name=None, starttime=None, endtime=None, page=0, page_size=PAGESIZE):
def _search(self, _id=None, name=None, starttime=None, endtime=None, state=None, page=0, page_size=PAGESIZE):
query = self.session.query(Rec)
if _id: query = query.filter_by(id=_id)
if name: query = query.filter_by(name=name)
if starttime: query = query.filter(Rec.starttime>starttime)
if endtime: query = query.filter(Rec.endtime<endtime)
if state: query = query.filter(state=state)
if page_size: query = query.limit(page_size)
if page: query = query.offset(page*page_size)