-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
29,590 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ test/version_tmp | |
tmp | ||
config.yaml | ||
vendor/bundle | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
Oops, something went wrong.