Skip to content

Commit

Permalink
TMP
Browse files Browse the repository at this point in the history
  • Loading branch information
ssig33 committed Sep 10, 2015
1 parent 1954c31 commit 2b68823
Show file tree
Hide file tree
Showing 13 changed files with 29,590 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ test/version_tmp
tmp
config.yaml
vendor/bundle
node_modules
Empty file added bundle.js
Empty file.
33 changes: 33 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
var buffer = require('vinyl-buffer');
var cssDir = 'stylesheets'

gulp.task('browserify', function() {
browserify('./javascripts/application.js', { debug: true })
.transform(babelify)
.bundle()
.on("error", function (err) { console.log("Error : " + err.message); })
.pipe(source('bundle.js'))
.pipe(gulp.dest('./lib/pig-media-server/views/'))
});

gulp.task('build', function(){
browserify('./javascripts/application.js', { debug: true })
.transform(babelify)
.bundle()
.on("error", function (err) { console.log("Error : " + err.message); })
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./public'))

});


gulp.task('watch', ['browserify'], function(){
gulp.watch('./javascripts/**/*.js', ['browserify']);
});
78 changes: 78 additions & 0 deletions javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
window.React = require('react');
window.$ = window.jQuery = require('jquery');

require('./components/head.js');

class Controller {
route(){
var result = {}
switch(location.pathname){
case "/":
result.page = "list";
result.api_url = null;
break;

case "/latest":
result.page = "list";
result.api_url = '/api/r/latest';
break;

}
return result;
}

params(){
var arg = new Object;
var pair = location.search.substring(1).split('&');
for(var i=0; pair[i]; i++) {
var kv = pair[i].split('=');
arg[kv[0]] = kv[1];
}
return arg;
}
}



class SearchBox extends React.Component {
render(){
return <form>
<input /><button>Search</button>
<a href='/latest'>Latest</a>
<a href='/config'>Config</a>
</form>
}
}

class Application extends React.Component {
constructor(props){
super(props);
this.controller = new Controller();

this.state = {
config: {},
session: {},
}
}

componentDidMount(){
$.get("/api/r/config").done((data)=>{ this.state.config = data; this.update_state(); })
$.get("/api/r/session").done((data)=>{ this.state.session = data; this.update_state(); })
console.log(this.controller.route().api_url);
}

update_state(){ this.setState(this.state); }

render(){

return <div>
<div id='all'>
<Head state={this.state} />
<SearchBox state={this.state}/>
</div>
</div>
}
}

React.render(<Application />, document.querySelector("#application"));

33 changes: 33 additions & 0 deletions javascripts/components/head.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class LoginAs extends React.Component {
render(){
return <span>Login as {this.props.user_id}</span>
}
}

class LoginLink extends React.Component {
render(){
return <a href='/sessions'>Login</a>
}
}

class Session extends React.Component {
render(){
return <div>
{this.props.state.session.user_id ?
<LoginAs user_id={this.props.state.session.user_id} /> :
<LoginLink />
}
</div>
}
}

class Head extends React.Component {
render(){
return <div>
<Session state={this.props.state} />
<h1>{this.props.state.config.page_title}</h1>
</div>
}
}

window.Head = Head;
45 changes: 45 additions & 0 deletions lib/pig-media-server/api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'active_support/concern'
module PigMediaServer
module API
extend ActiveSupport::Concern
def page
params[:page].to_i < 1 ? 1 : params[:page].to_i
end

def size
params[:size] ? params[:size].to_i : 50
end

def list_to_json list
list.map{|x| x.to_hash}.to_json
end

included do
get '/api/r/latest' do
content_type :json
list_to_json(Groonga['Files'].select.paginate([key: 'mtime', order: 'descending'], size: size, page: @page).map{|x| Pig.new(x)})
end

get '/api/r/custom' do
content_type :json
c = config['custom_list'][params[:name]]
list_to_json(Pig.find JSON.parse(open(c).read))
end

get '/api/r/search' do
content_type :json
list_to_json(Pig.search params.merge(page: page))
end

get '/api/r/config' do
content_type :json
config.to_json
end

get '/api/r/session' do
content_type :json
session.to_hash.to_json
end
end
end
end
5 changes: 4 additions & 1 deletion lib/pig-media-server/model/pig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def change_aspect_rate rate
open("#{self.config['user_data_path']}/rate/queue.txt", "a"){|x| x.puts "#{self.key} #{rate}"}
end


def to_hash(opts = {})
hash = {key: self.key, name: self.name, mtime: self.mtime, size: self.size, url: self.url, type: self.type}
hash
end

def self.find key
case key.class.to_s
Expand Down
4 changes: 4 additions & 0 deletions lib/pig-media-server/views/app.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
button, a, input{
margin-right: 3px;
}

body {
text-align:center;
background:black;
Expand Down
Loading

0 comments on commit 2b68823

Please sign in to comment.