Skip to content

Commit

Permalink
made it so project list returns a json object to the client
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Letter committed Jun 26, 2017
1 parent b0c9409 commit 4149e29
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/slycat/web/server/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def abspath(path):
dispatcher.connect("get-project", "/projects/:pid", slycat.web.server.handlers.get_project, conditions={"method" : ["GET"]})
dispatcher.connect("get-project-cache-object", "/projects/:pid/cache/:key", slycat.web.server.handlers.get_project_cache_object, conditions={"method" : ["GET"]})
dispatcher.connect("get-projects", "/projects", slycat.web.server.handlers.get_projects, conditions={"method" : ["GET"]})

dispatcher.connect("get-projects-list", "/projects_list", slycat.web.server.handlers.get_projects_list, conditions={"method" : ["GET"]})
#TODO: scrub sid
dispatcher.connect("get-remote-file", "/remotes/:hostname/file{path:.*}", slycat.web.server.handlers.get_remote_file, conditions={"method" : ["GET"]})

Expand Down
40 changes: 21 additions & 19 deletions packages/slycat/web/server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,28 @@ def get_projects(_=None):
:param _:
:return:
"""
accept = cherrypy.lib.cptools.accept(["text/html", "application/json"])
cherrypy.response.headers["content-type"] = accept
if 'Content-Type' in cherrypy.request.headers:
accept = cherrypy.request.headers.get('Content-Type')
if accept == "text/html":
context = {}
context["slycat-server-root"] = cherrypy.request.app.config["slycat-web-server"]["server-root"]
context["slycat-css-bundle"] = css_bundle()
context["slycat-js-bundle"] = js_bundle()
return slycat.web.server.template.render("slycat-projects.html", context)
context = {}
context["slycat-server-root"] = cherrypy.request.app.config["slycat-web-server"]["server-root"]
context["slycat-css-bundle"] = css_bundle()
context["slycat-js-bundle"] = js_bundle()
return slycat.web.server.template.render("slycat-projects.html", context)

if accept == "application/json":
database = slycat.web.server.database.couchdb.connect()
projects = [project for project in database.scan("slycat/projects") if
slycat.web.server.authentication.is_project_reader(
project) or slycat.web.server.authentication.is_project_writer(
project) or slycat.web.server.authentication.is_project_administrator(
project) or slycat.web.server.authentication.is_server_administrator()]
projects = sorted(projects, key=lambda x: x["created"], reverse=True)
return json.dumps({"revision": 0, "projects": projects})

@cherrypy.tools.json_out(on=True)
def get_projects_list(_=None):
"""
returns either and array of projects or html for displaying the projects
:param _:
:return:
"""
database = slycat.web.server.database.couchdb.connect()
projects = [project for project in database.scan("slycat/projects") if
slycat.web.server.authentication.is_project_reader(
project) or slycat.web.server.authentication.is_project_writer(
project) or slycat.web.server.authentication.is_project_administrator(
project) or slycat.web.server.authentication.is_server_administrator()]
projects = sorted(projects, key=lambda x: x["created"], reverse=True)
return {"revision": 0, "projects": projects}


@cherrypy.tools.json_in(on=True)
Expand Down
2 changes: 1 addition & 1 deletion web-server/js/slycat-changes-feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ define("slycat-changes-feed", ["slycat-server-root", "slycat-web-client", "URI",

var project_params = {
success : function(results){
results = JSON.parse(results);
// results = JSON.parse(results);
results.projects.forEach(function(project){
if(project._id in project_ids)
{
Expand Down
2 changes: 1 addition & 1 deletion web-server/js/slycat-web-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ define("slycat-web-client", ["slycat-server-root", "jquery", "URI"], function(se
$.ajax({
contentType: 'application/json',
type: 'GET',
url: server_root + 'projects',
url: server_root + 'projects_list',
success: function(result) {
if (params.success)
params.success(result);
Expand Down

0 comments on commit 4149e29

Please sign in to comment.