merge with devin
This commit is contained in:
commit
cf01e711dd
6 changed files with 99 additions and 4 deletions
9
Gemfile
9
Gemfile
|
@ -7,7 +7,7 @@ gem 'rails', '3.2.17'
|
||||||
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||||
|
|
||||||
#gem 'watir'
|
#gem 'watir'
|
||||||
#gem 'phantomjs'
|
gem 'phantomjs'
|
||||||
|
|
||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'redis', '2.2.2'
|
gem 'redis', '2.2.2'
|
||||||
|
@ -17,9 +17,13 @@ gem 'formula'
|
||||||
gem 'formtastic'
|
gem 'formtastic'
|
||||||
gem 'json'
|
gem 'json'
|
||||||
gem 'rails3-jquery-autocomplete'
|
gem 'rails3-jquery-autocomplete'
|
||||||
gem 'best_in_place'
|
gem 'best_in_place' #in-place editing
|
||||||
gem 'kaminari' # pagination
|
gem 'kaminari' # pagination
|
||||||
gem 'uservoice-ruby'
|
gem 'uservoice-ruby'
|
||||||
|
gem 'sidekiq' # worker processes
|
||||||
|
gem 'sinatra', require: false
|
||||||
|
gem 'slim'
|
||||||
|
|
||||||
gem 'paperclip'
|
gem 'paperclip'
|
||||||
gem 'aws-sdk'
|
gem 'aws-sdk'
|
||||||
|
|
||||||
|
@ -58,3 +62,4 @@ gem 'jquery-rails', '2.1.2'
|
||||||
|
|
||||||
# To use debugger
|
# To use debugger
|
||||||
# gem 'ruby-debug19', :require => 'ruby-debug'
|
# gem 'ruby-debug19', :require => 'ruby-debug'
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ class MappingsController < ApplicationController
|
||||||
def create
|
def create
|
||||||
@mapping = Mapping.new(params[:mapping])
|
@mapping = Mapping.new(params[:mapping])
|
||||||
|
|
||||||
|
@mapping.map.touch(:updated_at)
|
||||||
|
|
||||||
if @mapping.save
|
if @mapping.save
|
||||||
render json: @mapping, status: :created
|
render json: @mapping, status: :created
|
||||||
else
|
else
|
||||||
|
@ -26,6 +28,8 @@ class MappingsController < ApplicationController
|
||||||
def update
|
def update
|
||||||
@mapping = Mapping.find(params[:id])
|
@mapping = Mapping.find(params[:id])
|
||||||
|
|
||||||
|
@mapping.map.touch(:updated_at)
|
||||||
|
|
||||||
if @mapping.update_attributes(params[:mapping])
|
if @mapping.update_attributes(params[:mapping])
|
||||||
head :no_content
|
head :no_content
|
||||||
else
|
else
|
||||||
|
@ -36,8 +40,12 @@ class MappingsController < ApplicationController
|
||||||
# DELETE /mappings/1.json
|
# DELETE /mappings/1.json
|
||||||
def destroy
|
def destroy
|
||||||
@mapping = Mapping.find(params[:id])
|
@mapping = Mapping.find(params[:id])
|
||||||
|
@map = @mapping.map
|
||||||
|
|
||||||
@mapping.destroy
|
@mapping.destroy
|
||||||
|
|
||||||
|
@map.touch(:updated_at)
|
||||||
|
|
||||||
head :no_content
|
head :no_content
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,8 @@ class Map < ActiveRecord::Base
|
||||||
has_many :topics, :through => :topicmappings
|
has_many :topics, :through => :topicmappings
|
||||||
has_many :synapses, :through => :synapsemappings
|
has_many :synapses, :through => :synapsemappings
|
||||||
|
|
||||||
|
after_touch :save_screenshot
|
||||||
|
|
||||||
# This method associates the attribute ":image" with a file attachment
|
# This method associates the attribute ":image" with a file attachment
|
||||||
has_attached_file :screenshot, :styles => {
|
has_attached_file :screenshot, :styles => {
|
||||||
:thumb => ['188x126#', :png],
|
:thumb => ['188x126#', :png],
|
||||||
|
@ -76,7 +78,7 @@ class Map < ActiveRecord::Base
|
||||||
json[:updated_at] = self.updated_at_str
|
json[:updated_at] = self.updated_at_str
|
||||||
json
|
json
|
||||||
end
|
end
|
||||||
|
|
||||||
##### PERMISSIONS ######
|
##### PERMISSIONS ######
|
||||||
|
|
||||||
# returns false if user not allowed to 'show' Topic, Synapse, or Map
|
# returns false if user not allowed to 'show' Topic, Synapse, or Map
|
||||||
|
@ -105,4 +107,15 @@ class Map < ActiveRecord::Base
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def save_screenshot
|
||||||
|
# TODO - this will grab a map every single frickin' time a map is touched
|
||||||
|
# we need a system to throttle the amount to 1/hour or something like that
|
||||||
|
# maybe have a flag - last time this map was screenshotted
|
||||||
|
# don't update if it was less than an hour ago
|
||||||
|
# except this has the issue of a user updating map 7x, and it only screenshotting after
|
||||||
|
# the first time. We only want it to screenhsot the 7th time.
|
||||||
|
# We need to store a timestamp somewhere and do processing every hour, I think.
|
||||||
|
GrabMapScreenshotWorker.perform_async(self.id)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
10
app/workers/grab_map_screenshot_worker.rb
Normal file
10
app/workers/grab_map_screenshot_worker.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# app/workers/grab_map_screenshot_worker.rb
|
||||||
|
class GrabMapScreenshotWorker
|
||||||
|
include Sidekiq::Worker
|
||||||
|
|
||||||
|
def perform(map_id)
|
||||||
|
Phantomjs.run('./script/phantomjs-save-screenshot.js', map_id.to_s) { |line|
|
||||||
|
puts line
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,6 +1,11 @@
|
||||||
|
require 'sidekiq/web'
|
||||||
|
|
||||||
Metamaps::Application.routes.draw do
|
Metamaps::Application.routes.draw do
|
||||||
|
|
||||||
root to: 'main#home', via: :get
|
root to: 'main#home', via: :get
|
||||||
|
|
||||||
|
#To debug sidekiq and monitor processes, enable this route
|
||||||
|
#mount Sidekiq::Web, at: '/sidekiq'
|
||||||
|
|
||||||
match 'request', to: 'main#requestinvite', via: :get, as: :request
|
match 'request', to: 'main#requestinvite', via: :get, as: :request
|
||||||
|
|
||||||
|
|
54
script/phantomjs-save-screenshot.js
Executable file
54
script/phantomjs-save-screenshot.js
Executable file
|
@ -0,0 +1,54 @@
|
||||||
|
//parse arguments passed from command line (or more likely, from rails)
|
||||||
|
var system = require('system');
|
||||||
|
var args = system.args;
|
||||||
|
if (args.length <= 1) {
|
||||||
|
phantom.exit();
|
||||||
|
throw new Error("no arguments supplied on command line");
|
||||||
|
}//if
|
||||||
|
|
||||||
|
//configurable variables - CHANGE ME
|
||||||
|
var mapID = args[1];
|
||||||
|
var url = 'http://localhost:3000/maps/' + mapID;
|
||||||
|
var width = 400;
|
||||||
|
var height = 400;
|
||||||
|
var thumbsDirRelative = 'app/assets/images/map_thumbnails';
|
||||||
|
|
||||||
|
//set up writing to filesystem
|
||||||
|
var fs = require('fs');
|
||||||
|
var thumbsDirectory = fs.workingDirectory + '/' + thumbsDirRelative;
|
||||||
|
if (!fs.isDirectory(thumbsDirectory)) {
|
||||||
|
fs.makeDirectory(thumbsDirectory);
|
||||||
|
}//if
|
||||||
|
|
||||||
|
//set up page and the area we'll render as a PNG
|
||||||
|
var page = require('webpage').create();
|
||||||
|
page.viewportSize = {
|
||||||
|
width: width,
|
||||||
|
height: height
|
||||||
|
};
|
||||||
|
page.clipRect = {
|
||||||
|
top: 32,
|
||||||
|
left: 32,
|
||||||
|
width: width - 32,
|
||||||
|
height: height - 32
|
||||||
|
};
|
||||||
|
page.open(url, function (status) {
|
||||||
|
if (status === 'success') {
|
||||||
|
//since this isn't evaluateAsync, it should also ensure the asynchronous
|
||||||
|
//js stuff is loaded too, hopefully?
|
||||||
|
page.evaluate(function() {
|
||||||
|
$(document).ready(function(){
|
||||||
|
$('.upperLeftUI, .upperRightUI, .mapControls, .infoAndHelp, #barometer_tab, .footer').hide();
|
||||||
|
});//document.ready
|
||||||
|
});//page.evaluate
|
||||||
|
|
||||||
|
//render page into map_thumbnails directory
|
||||||
|
var filename = thumbsDirectory + '/map' + mapID + '.png';
|
||||||
|
page.render(filename, 'PNG');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//failed to load
|
||||||
|
}//if
|
||||||
|
|
||||||
|
phantom.exit();
|
||||||
|
});
|
Loading…
Reference in a new issue