diff --git a/.gitignore b/.gitignore index 53ffa91..e85cd5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store env +shows.db yarn.lock */yarn.lock diff --git a/client/app/components/MovieObject.jsx b/client/app/components/MovieObject.jsx index 64ea04c..d78747e 100644 --- a/client/app/components/MovieObject.jsx +++ b/client/app/components/MovieObject.jsx @@ -11,6 +11,9 @@ import RequestButton from './buttons/request_button.jsx'; import { fetchJSON } from './http.jsx'; +import Interactive from 'react-interactive'; + + class MovieObject { constructor(object) { this.id = object.id; @@ -42,6 +45,13 @@ class MovieObject { notify.show(this.title + ' requested!', 'success', 3000); } + invertButtonColors(event) { + const event_type = event.type; + if (event_type) + console.log('test') + console.log(event.type) + } + getElement(index) { const element_key = index + this.id; @@ -55,11 +65,26 @@ class MovieObject { var foundInPlex; if (this.matchedInPlex) { - foundInPlex = ; + foundInPlex = {this.requestExisting(this)}} + style={movieStyle.requestButton}> + + Request Anyway + ; } else { - foundInPlex = ; + foundInPlex = {this.requestMovie()}} + onMouseOver={() => {this.invertButtonColors(event)}} + style={movieStyle.requestButton}> + + + Request + ; } if (this.type === 'movie') @@ -105,7 +130,14 @@ class MovieObject {
{foundInPlex} - + + + Info +
diff --git a/client/app/components/styles/movieObjectStyle.jsx b/client/app/components/styles/movieObjectStyle.jsx index 627d7dd..c16a89f 100644 --- a/client/app/components/styles/movieObjectStyle.jsx +++ b/client/app/components/styles/movieObjectStyle.jsx @@ -62,8 +62,9 @@ export default { requestButton: { color: '#e9a131', marginRight: '10px', - background: 'white', + backgroundColor: 'white', border: '#e9a131 2px solid', + borderColor: '#e9a131', borderRadius: '4px', textAlign: 'center', padding: '10px', @@ -74,10 +75,15 @@ export default { cursor: 'pointer' }, + requestButton_hover: { + backgroundColor: '#e9a131', + color: 'white', + }, + tmdbButton: { color: '#00d17c', marginRight: '10px', - background: 'white', + backgroundColor: 'white', border: '#00d17c 2px solid', borderRadius: '4px', textAlign: 'center', @@ -89,6 +95,11 @@ export default { cursor: 'pointer' }, + tmdbButton_hover: { + backgroundColor: '#00d17c', + color: 'white', + }, + row: { width: '100%' }, diff --git a/client/package.json b/client/package.json index 7d36795..f166ff8 100644 --- a/client/package.json +++ b/client/package.json @@ -19,6 +19,7 @@ "react-burger-menu": "^2.1.6", "react-dom": "^15.5.4", "react-infinite-scroller": "^1.0.15", + "react-interactive": "^0.8.1", "react-notify-toast": "^0.3.2", "react-redux": "^5.0.6", "react-responsive": "^1.3.4", diff --git a/seasoned_api/.gitignore b/seasoned_api/.gitignore index 922c3ee..9f7246b 100644 --- a/seasoned_api/.gitignore +++ b/seasoned_api/.gitignore @@ -60,5 +60,4 @@ typings/ # - - - - - # My own gitignore files and folders -shows.db conf diff --git a/seasoned_api/src/database/database.js b/seasoned_api/src/database/database.js index 00c9d98..8e509df 100644 --- a/seasoned_api/src/database/database.js +++ b/seasoned_api/src/database/database.js @@ -10,6 +10,6 @@ const database = new SqliteDatabase(configuration.get('database', 'host')); */ Promise.resolve() .then(() => database.connect()) -// .then(() => database.setUp()); +.then(() => database.setUp()); module.exports = database; diff --git a/seasoned_api/src/database/schemas/setup.sql b/seasoned_api/src/database/schemas/setup.sql new file mode 100644 index 0000000..5d9d8fd --- /dev/null +++ b/seasoned_api/src/database/schemas/setup.sql @@ -0,0 +1,57 @@ +CREATE TABLE IF NOT EXISTS user ( + user_name varchar(127) UNIQUE, + password varchar(127), + email varchar(127) UNIQUE, + primary key (user_name) +); + +CREATE TABLE IF NOT EXISTS cache ( + key varchar(255), + value blob, + time_to_live INTEGER DEFAULT 60, + created_at DATE DEFAULT (datetime('now','localtime')), + primary key(key) +); + +CREATE TABLE IF NOT EXISTS search_history ( + id integer, + user_name varchar(127), + search_query varchar(255), + primary key (id), + foreign key(user_name) REFERENCES user(user_name) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS requests( + id TEXT, + name TEXT, + year NUMBER, + poster_path TEXT DEFAULT NULL, + background_path TEXT DEFAULT NULL, + requested_by TEXT, + ip TEXT, + requested_date DATE DEFAULT CURRENT_DATE NOT NULL, + status CHAR(25) DEFAULT 'requested' NOT NULL, + user_agent CHAR(255) DEFAULT NULL, + type CHAR(50) DEFAULT 'movie' +); + + +CREATE TABLE IF NOT EXISTS stray_eps( + id TEXT UNIQUE, + parent TEXT, + path TEXT, + name TEXT, + season NUMBER, + episode NUMBER, + video_files TEXT, + subtitles TEXT, + trash TEXT, + verified BOOLEAN DEFAULT 0, + primary key(id) +); + +CREATE TABLE IF NOT EXISTS shows( + show_names TEXT, + date_added DATE, + date_modified DATE DEFUALT CURRENT_DATE NOT NULL +); \ No newline at end of file diff --git a/seasoned_api/src/database/sqliteDatabase.js b/seasoned_api/src/database/sqliteDatabase.js index 3d0c5a4..5ac1330 100644 --- a/seasoned_api/src/database/sqliteDatabase.js +++ b/seasoned_api/src/database/sqliteDatabase.js @@ -4,30 +4,80 @@ const sqlite = require('sqlite'); class SqliteDatabase { - constructor(host) { - this.host = host; - this.connection = sqlite; + constructor(host) { + this.host = host; + this.connection = sqlite; + this.schemaDirectory = path.join(__dirname, 'schemas'); + } - // this.schemaDirectory = path.join(__dirname, 'schemas'); - } + /** + * Connect to the database. + * @returns {Promise} succeeds if connection was established + */ + connect() { + return Promise.resolve() + .then(() => sqlite.open(this.host)) + .then(() => sqlite.exec('pragma foreign_keys = on;')); + } - connect() { - return Promise.resolve() - .then(() => sqlite.open(this.host)) - .then(() => sqlite.exec('pragma foreign_keys = on;')); - } + /** + * Run a SQL query against the database. + * @param {String} sql SQL query + * @param {Array} parameters in the SQL query + * @returns {Promise} + */ + run(sql, parameters) { + return this.connection.run(sql, parameters); + } - all(sql, parameters) { - return this.connection.all(sql, parameters); - } + /** + * Run a SQL query against the database and retrieve all the rows. + * @param {String} sql SQL query + * @param {Array} parameters in the SQL query + * @returns {Promise} + */ + all(sql, parameters) { + return this.connection.all(sql, parameters); + } - get(sql, parameters) { - return this.connection.get(sql, parameters); - } + /** + * Run a SQL query against the database and retrieve one row. + * @param {String} sql SQL query + * @param {Array} parameters in the SQL query + * @returns {Promise} + */ + get(sql, parameters) { + return this.connection.get(sql, parameters); + } - run(sql, parameters) { - return this.connection.run(sql, parameters); - } + /** + * Run a SQL query against the database and retrieve the status. + * @param {String} sql SQL query + * @param {Array} parameters in the SQL query + * @returns {Promise} + */ + execute(sql) { + return this.connection.exec(sql); + } + + /** + * Setup the database by running setup.sql file in schemas/. + * @returns {Promise} + */ + setUp() { + const setupSchema = this.readSqlFile('setup.sql'); + return this.execute(setupSchema); + } + + /** + * Returns the file contents of a SQL file in schemas/. + * @returns {String} + */ + readSqlFile(filename) { + const schemaPath = path.join(this.schemaDirectory, filename); + const schema = fs.readFileSync(schemaPath).toString('utf-8'); + return schema; + } } module.exports = SqliteDatabase; diff --git a/seasoned_api/src/plex/requestRepository.js b/seasoned_api/src/plex/requestRepository.js index 94bfdc8..ffddd12 100644 --- a/seasoned_api/src/plex/requestRepository.js +++ b/seasoned_api/src/plex/requestRepository.js @@ -22,7 +22,7 @@ class RequestRepository { constructor(cache, database) { this.database = database || establishedDatabase; this.queries = { - 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)", + 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)", 'fetchRequstedItems': "SELECT * FROM requests", 'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?", } @@ -117,7 +117,7 @@ class RequestRepository { user = 'NULL'; console.log(user) // Add request to database - this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, user, ip, user_agent, movie.type]) + this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, movie.background, user, ip, user_agent, movie.type]) // create reusable transporter object using the default SMTP transport