Skip to content

Commit

Permalink
Another SQL UPDATE test
Browse files Browse the repository at this point in the history
  • Loading branch information
codemacabre committed Aug 15, 2017
1 parent 0e3f6b7 commit f9739b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 1 addition & 2 deletions app.js
Expand Up @@ -14,8 +14,7 @@ var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
Expand Down
18 changes: 13 additions & 5 deletions public/sandbox/js/map.js
Expand Up @@ -30,10 +30,15 @@ window.onload = function() {

var getLat, getLng, getSelectedID, getName, getDesc, getUrl;
var editedData = '';
var builtSQLQuery;
var currentData, currentZoom, currentCenter;
var precision;
var userAPI = process.env.CARTO_API_CM;

var CartoDB = require('cartodb');
var sql = new CartoDB.SQL({
user: CodeMacabre,
api_key: process.env.CARTO_API_CM
});
var builtSQLQuery;

// Initialise map
var initMap = function () {
Expand Down Expand Up @@ -154,9 +159,12 @@ window.onload = function() {
editedData += 'name=\'' + editName.value + '\',description=\'' + editDesc.value + '\',url=\'' + editUrl.value + '\'+';
}
// Submit SQL query
builtSQLQuery = 'https://codemacabre.carto.com/api/v2/sql?q=UPDATE+test_dataset+SET+' + editedData + 'WHERE+cartodb_id+=+' + getSelectedID + '&api_key=' + userAPI;
location.href = builtSQLQuery;
alert('Edited data submitted! Refresh page to update or make another edit.');
builtSQLQuery = 'UPDATE+test_dataset+SET+' + editedData + 'WHERE+cartodb_id+=+' + getSelectedID + '&api_key=' + userAPI;
sql.execute(builtSQLQuery)
.done(function(data) {
alert('Edited data submitted! Refresh page to update or make another edit.');
});

}
initMap();
};

0 comments on commit f9739b2

Please sign in to comment.