Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use http to read and write settings

  • Loading branch information...
commit efa6de27f5c29e41c90e0a0396a07bc2acfc9517 1 parent 75e8419
@fjakobs fjakobs authored
View
3  configs/default.js
@@ -202,7 +202,8 @@ var config = [
},
"./cloud9.ide.shell",
"./cloud9.ide.state",
- "./cloud9.ide.watcher"
+ "./cloud9.ide.watcher",
+ "./cloud9.routes"
];
module.exports = config;
View
43 plugins-client/cloud9.core/www/core/settings.js
@@ -48,19 +48,11 @@ module.exports = {
this.model.data.setAttribute("time", new Date().getTime());
var data = this.model.data && apf.xmldb.cleanXml(this.model.data.xml) || "";
- if (ide.onLine) {
- this.dirty = false;
-
- ide.send({
- command: "settings",
- action: "set",
- settings: data
- });
- ide.dispatchEvent("track_action", {
- type: "save settings",
- settings: data
- });
- }
+ apf.ajax(window.location.pathname.replace(/\/$/, "") + "/api/settings", {
+ method : "POST",
+ contentType : "text/plain",
+ data : data
+ });
},
load : function(xml){
@@ -157,31 +149,6 @@ module.exports = {
else if (cloud9config.settings)
xml = cloud9config.settings;
- if (!xml) {
- ide.addEventListener("socketMessage", function(e){
- if (e.message.type == "settings") {
- var settings = e.message.settings;
- if (!settings || settings == "defaults")
- settings = template;
-
- _self.load(settings);
- initEvents();
-
- ide.removeEventListener("socketMessage", arguments.callee);
- }
- });
-
- if (ide.onLine === true) {
- ide.send({command: "settings", action: "get"});
- }
- else {
- ide.addEventListener("afteronline", function() {
- ide.send({command: "settings", action: "get"});
- });
- }
- return;
- }
-
this.load(xml);
initEvents();
View
2  plugins-server/cloud9.ide.settings/package.json
@@ -6,8 +6,8 @@
"plugin": {
"consumes": [
- "ide",
"vfs",
+ "ide-routes",
"sandbox"
]
}
View
109 plugins-server/cloud9.ide.settings/settings.js
@@ -7,77 +7,80 @@
"use strict";
-var Plugin = require("../cloud9.core/plugin");
var fsnode = require("vfs-nodefs-adapter");
-var util = require("util");
var assert = require("assert");
+var Connect = require("connect");
+var error = require("http-error");
-var name = "settings";
-
-var FS;
-var SETTINGS_PATH;
-
-var trimFilePrefix;
var locationsToSwap = {"files" : "active", "file" : "path", "tree_selection": "path" };
var propertiesToSwap= ["projecttree", "tabcycle", "recentfiles"];
module.exports = function setup(options, imports, register) {
assert(options.settingsPath, "option 'settingsPath' is required");
- SETTINGS_PATH = options.settingsPath;
+ var settingsPath = options.settingsPath;
imports.sandbox.getProjectDir(function(err, projectDir) {
- FS = fsnode(imports.vfs, projectDir);
+ var fs = fsnode(imports.vfs, projectDir);
// If absolute settings path option is set we use that path and NodeJS's FS.
// This is needed by c9local where settings file cannot be stored at `/.settings`.
if (typeof options.absoluteSettingsPath !== "undefined") {
- FS = require("fs");
- FS.exists = require("path").exists;
- SETTINGS_PATH = options.absoluteSettingsPath;
+ fs = require("fs");
+ fs.exists = require("path").exists;
+ settingsPath = options.absoluteSettingsPath;
}
- trimFilePrefix = options.trimFilePrefix;
- imports.ide.register(name, SettingsPlugin, register);
+ new SettingsPlugin(fs, settingsPath, options.trimFilePrefix).registerRoutes(imports["ide-routes"]);
+
+ register();
});
};
-var SettingsPlugin = module.exports.SettingsPlugin = function(ide, workspace) {
- Plugin.call(this, ide, workspace);
- this.hooks = ["command"];
- this.name = name;
- this.fs = FS;
- this.settingsPath = SETTINGS_PATH;
+var SettingsPlugin = module.exports.SettingsPlugin = function(fs, settingsPath, trimFilePrefix) {
+ this.fs = fs;
+ this.settingsPath = settingsPath;
+ this.trimFilePrefix = trimFilePrefix;
};
-util.inherits(SettingsPlugin, Plugin);
-
(function() {
this.counter = 0;
- this.command = function(user, message, client) {
- if (message.command != "settings")
- return false;
-
- var _self = this;
- if (message.action == "get") {
- this.loadSettings(user, function(err, settings) {
- client.send(JSON.stringify({
- "type": "settings",
- "settings": err || !settings ? "defaults" : settings
- }));
- });
- }
- else if (message.action == "set") {
- this.storeSettings(user, message.settings, function(err) {
- if (err)
- _self.error(err, 500, message, client);
- });
- }
- return true;
+ this.registerRoutes = function(connect) {
+ var self = this;
+
+ connect.use("/settings", function(req, res, next) {
+ console.log("SETTINGS", req.url)
+ if (req.method !== "GET" && req.method !== "POST")
+ return next();
+
+ if (req.method == "GET") {
+ self.loadSettings(function(err, settings) {
+ if (err) return next(err);
+
+ res.writeHead(200, {
+ "Content-Type": "application/json"
+ });
+ res.end(settings);
+ });
+ }
+ else if (req.method == "POST") {
+ //console.log(req.body);
+ var settings = "";
+ req.on("data", function(data) {
+ settings += data;
+ })
+ req.on("end", function() {
+ self.storeSettings(settings, function(err) {
+ res.writeHead(err ? 500 : 200);
+ res.end(err || "");
+ });
+ });
+ }
+ });
};
- this.loadSettings = function(user, callback) {
- // console.log("load settings", this.settingsPath);
+ this.loadSettings = function(callback) {
+ console.log("load settings", this.settingsPath);
var self = this;
this.fs.exists(this.settingsPath, function(exists) {
if (exists) {
@@ -88,13 +91,13 @@ util.inherits(SettingsPlugin, Plugin);
}
// for local version, we need to pluck the paths in settings prepended with username + workspace id (short)
- if (trimFilePrefix !== undefined) {
+ if (self.trimFilePrefix !== undefined) {
var attrSet = '="';
for (var l in locationsToSwap) {
var attribute = locationsToSwap[l] + attrSet;
- settings = settings.replace(new RegExp(attribute + "/workspace", "g"), attribute + trimFilePrefix + "/workspace");
+ settings = settings.replace(new RegExp(attribute + "/workspace", "g"), attribute + self.trimFilePrefix + "/workspace");
}
propertiesToSwap.forEach(function (el, idx, arr) {
@@ -103,7 +106,7 @@ util.inherits(SettingsPlugin, Plugin);
if (openTagPos > 0 && closeTagPos > 0) {
var originalPath = settings.substring(openTagPos, closeTagPos);
- var newPath = originalPath.replace(new RegExp("/workspace", "g"), trimFilePrefix + "/workspace");
+ var newPath = originalPath.replace(new RegExp("/workspace", "g"), self.trimFilePrefix + "/workspace");
settings = settings.replace(originalPath, newPath);
}
@@ -119,20 +122,20 @@ util.inherits(SettingsPlugin, Plugin);
});
};
- this.storeSettings = function(user, settings, callback) {
+ this.storeSettings = function(settings, callback) {
var self = this;
- // console.log("store settings", this.settingsPath);
+ console.log("store settings", this.settingsPath);
// Atomic write (write to tmp file and rename) so we don't get corrupted reads if at same time.
var tmpPath = self.settingsPath + "~" + new Date().getTime() + "-" + ++this.counter;
// for local version, we need to rewrite the paths in settings to store as "/workspace"
- if (trimFilePrefix !== undefined) {
+ if (self.trimFilePrefix !== undefined) {
var attrSet = '="';
for (var l in locationsToSwap) {
var attribute = locationsToSwap[l] + attrSet;
- settings = settings.replace(new RegExp(attribute + trimFilePrefix, "g"), attribute);
+ settings = settings.replace(new RegExp(attribute + self.trimFilePrefix, "g"), attribute);
}
propertiesToSwap.forEach(function (el, idx, arr) {
@@ -141,7 +144,7 @@ util.inherits(SettingsPlugin, Plugin);
if (openTagPos > 0 && closeTagPos > 0) {
var originalPath = settings.substring(openTagPos, closeTagPos);
- var newPath = originalPath.replace(new RegExp(trimFilePrefix, "g"), "");
+ var newPath = originalPath.replace(new RegExp(self.trimFilePrefix, "g"), "");
settings = settings.replace(originalPath, newPath);
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.