Browse Source

more ombi homepage work - shows dont work yet

causefx 8 years ago
parent
commit
88c748756e
5 changed files with 170 additions and 26 deletions
  1. 53 19
      api/functions/homepage-connect-functions.php
  2. 1 1
      api/functions/homepage-functions.php
  3. 12 0
      css/organizr.css
  4. 15 3
      js/custom.js
  5. 89 3
      js/functions.js

+ 53 - 19
api/functions/homepage-connect-functions.php

@@ -1096,7 +1096,7 @@ function ombiAPI($array){
     ombiAction($array['data']['id'],$array['data']['action'],$array['data']['type']);
 }
 function ombiAction($id, $action, $type) {
-    if($GLOBALS['homepageOmbiEnabled'] && !empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && qualifyRequest('1')){
+    if($GLOBALS['homepageOmbiEnabled'] && !empty($GLOBALS['ombiURL']) && !empty($GLOBALS['ombiToken']) && qualifyRequest($GLOBALS['homepageOmbiAuth'])){
         $url = qualifyURL($GLOBALS['ombiURL']);
         $headers = array(
     		"Accept" => "application/json",
@@ -1110,35 +1110,69 @@ function ombiAction($id, $action, $type) {
     		case 'season':
     		case 'tv':
     			$type = 'tv';
+                $add = array(
+                    'tvdDbId' => $id,
+                    'requestAll' => true,
+                    'latestSeason' => true,
+                    'firstSeason' => true
+                );
     			break;
     		default:
     			$type = 'movie';
+                $add = array("theMovieDbId" => (int)$id);
     			break;
     	}
+        $success['head'] = $headers;
+        $success['act'] = $action;
+        $success['data'] = $data;
+        $success['add'] = $add;
+        $success['type'] = $type;
         try{
             $options = (localURL($url)) ? array('verify' => false ) : array();
             switch ($action) {
-        		case 'approve':
-        			$response = Requests::post($url."/api/v1/Request/".$type."/approve", $headers, json_encode($data), $options);
-        			break;
-        		case 'available':
-    				$response = Requests::post($url."/api/v1/Request/".$type."/available", $headers, json_encode($data), $options);
-    				break;
-        		case 'unavailable':
-        			$response = Requests::post($url."/api/v1/Request/".$type."/unavailable", $headers, json_encode($data), $options);
-        			break;
-        		case 'deny':
-        			$response = Requests::put($url."/api/v1/Request/".$type."/deny", $headers, json_encode($data), $options);
-        			break;
-        		case 'delete':
-        			$response = Requests::delete($url."/api/v1/Request/".$type."/".$id, $headers, $options);
-        			break;
+                case 'add':
+                    if(isset($_COOKIE['Auth'])){
+                        $headers = array(
+                            "Accept" => "application/json",
+                            "Content-Type" => "application/json",
+                            "Authorization" => "Bearer ".$_COOKIE['Auth']
+                        );
+                        $success['head'] = $headers;
+                    }else{
+                        return false;
+                    }
+                    $response = Requests::post($url."/api/v1/Request/".$type, $headers, json_encode($add), $options);
+                    break;
         		default:
-        			# code...
-        			break;
+        			if(qualifyRequest(1)){
+                        switch ($action) {
+                    		case 'approve':
+                    			$response = Requests::post($url."/api/v1/Request/".$type."/approve", $headers, json_encode($data), $options);
+                    			break;
+                    		case 'available':
+                				$response = Requests::post($url."/api/v1/Request/".$type."/available", $headers, json_encode($data), $options);
+                				break;
+                    		case 'unavailable':
+                    			$response = Requests::post($url."/api/v1/Request/".$type."/unavailable", $headers, json_encode($data), $options);
+                    			break;
+                    		case 'deny':
+                    			$response = Requests::put($url."/api/v1/Request/".$type."/deny", $headers, json_encode($data), $options);
+                    			break;
+                    		case 'delete':
+                    			$response = Requests::delete($url."/api/v1/Request/".$type."/".$id, $headers, $options);
+                    			break;
+                            default:
+                                return false;
+                            }
+
+                    }
+        		break;
         	}
+            $success['api'] = $response;
+            $success['bd'] = $response->body;
+            $success['hd'] = $response->headers;
             if($response->success){
-                $success = true;
+                $success['ok'] = true;
             }
         }catch( Requests_Exception $e ) {
             writeLog('error', 'OMBI Connect Function - Error: '.$e->getMessage(), 'SYSTEM');

+ 1 - 1
api/functions/homepage-functions.php

@@ -1341,7 +1341,7 @@ function getHomepageList(){
 					array(
                         'type' => 'switch',
                         'name' => 'ombiLimitUser',
-                        'label' => 'Enable',
+                        'label' => 'Limit to User',
                         'value' => $GLOBALS['ombiLimitUser']
                     ),
                     array(

+ 12 - 0
css/organizr.css

@@ -268,3 +268,15 @@ background: #2cabe3;
 	-moz-animation-iteration-count: infinite;
   -o-animation-iteration-count: infinite;
 }
+@media (max-width: 767px){
+  img.lazyload.resultImages {
+      height: 300px !important;
+      object-fit: contain;
+  }
+}
+@media (min-width: 768px){
+  img.lazyload.resultImages {
+      height: 300px !important;
+      object-fit: cover;
+  }
+}

+ 15 - 3
js/custom.js

@@ -314,6 +314,7 @@ function pageLoad(){
       callbacks: {
         beforeOpen: function() {
            this.st.mainClass = this.st.el.attr('data-effect');
+           this.st.focus = '#request-input';
         }
       },
       midClick: true // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source.
@@ -1624,17 +1625,17 @@ $(document).on('click', "a[class*=ID-]", function(){
 // request filter
 $(document).on("change", ".filter-request-input", function () {
     $('.request-item').parent().removeClass('hidden');
-    var badArray = [];
+    var filterArray = [];
     $('.filter-request-input').each(function () {
         var value = $(this).prop('checked');
         var filter = $(this).attr('data-filter');
         if(value == false){
-            badArray.push('.'+filter);
+            filterArray.push('.'+filter);
         }
     });
     $('.request-item').each(function () {
         var element = $(this);
-        var string = badArray.join(', ');
+        var string = filterArray.join(', ');
         if(element.is(string)){
             element.parent().addClass('hidden');
         }
@@ -1644,6 +1645,17 @@ $(document).on("change", ".filter-request-input", function () {
     owl.trigger('refresh.owl.carousel');
     owl.trigger('to.owl.carousel',0);
 });
+//search ombi
+var typingTimer;
+//on keyup, start the countdown
+$(document).on('keyup', '#request-input', function () {
+  clearTimeout(typingTimer);
+  typingTimer = setTimeout(doneTyping, 750);
+});
+//on keydown, clear the countdown
+$(document).on('keydown', '#request-input', function () {
+  clearTimeout(typingTimer);
+});
 /* ===== Open-Close Right Sidebar ===== */
 
 $(document).on("click", ".right-side-toggle", function () {

+ 89 - 3
js/functions.js

@@ -2253,7 +2253,7 @@ function buildPlaylist(array, type){
 		$.each(array.content, function(i,v) {
 			count ++;
 			first = (count == 1) ? v.title : first;
-			hidden = (count == 1) ? '' : ' hidden';
+			hidden = (count == 1) ? '' : ' owl-hidden hidden';
 			dropdown += `<li><a data-filter="`+i+`" server-filter="`+type+`" data-title="`+encodeURI(v.title)+`" href="javascript:void(0);">`+v.title+`</a></li>`;
 
 			items += `
@@ -2265,7 +2265,7 @@ function buildPlaylist(array, type){
 		});
 		var builtDropdown = `
 		<button aria-expanded="false" data-toggle="dropdown" class="btn btn-info dropdown-toggle waves-effect waves-light" type="button">
-			<i class="fa fa-filter m-r-5"></i><span class="caret"></span>
+			<i class="mdi mdi-playlist-play m-r-5"></i><span class="caret"></span>
 		</button>
 		<ul role="menu" class="dropdown-menu playlist-filter">
 			`+dropdown+`
@@ -2299,6 +2299,7 @@ function buildRequest(array){
 		<button aria-expanded="false" data-toggle="dropdown" class="btn btn-info dropdown-toggle waves-effect waves-light" type="button">
 			<i class="fa fa-filter m-r-5"></i><span class="caret"></span>
 		</button>
+		<button href="#new-request" class="btn btn-info waves-effect waves-light inline-popups" data-effect="mfp-zoom-out"><i class="fa fa-plus m-l-5"></i></button>
 		<div role="menu" class="dropdown-menu request-filter">
 			<div class="checkbox checkbox-success m-l-20 checkbox-circle">
 				<input id="request-filter-available" data-filter="request-available" class="filter-request-input" type="checkbox" checked="">
@@ -2352,8 +2353,82 @@ function buildRequest(array){
             </div>
         </div>
     </div>
+	<div id="new-request" class="white-popup mfp-with-anim mfp-hide">
+		<div class="col-md-8 col-md-offset-2">
+			<div class="white-box m-b-0">
+				<div class="form-group">
+					<label class="col-md-12"><span lang="en" class="help">Request Show or Movie</span></label>
+					<div id="request-input-div" class="col-md-12">
+						<input id="request-input" type="text" class="form-control">
+					</div>
+					<div class="clearfix"></div>
+				</div>
+				<div id="request-results" class="row el-element-overlay"></div>
+			</div>
+		</div>
+	</div>
 	` : '';
 }
+function buildRequestResult(array){
+	//var result = (typeof array !== 'undefined') ? true : false;
+	var results = '';
+	if(array.length == 0){
+		return '<tr><td class="max-texts" lang="en">Nothing in queue</td></tr>';
+	}
+	$.each(array, function(i,v) {
+		if(v.media_type == 'tv' || v.media_type == 'movie'){
+			var bg = (v.poster_path !== null) ? `https://image.tmdb.org/t/p/w300/`+v.poster_path : 'plugins/images/cache/no-list.png';
+			var top = (v.title) ? v.title : (v.original_title) ? v.original_title : (v.original_name) ? v.original_name : '';
+			var bottom = (v.release_date) ? v.release_date : (v.first_air_date) ? v.first_air_date : '';
+			results += `
+			<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
+	            <div class="white-box">
+	                <div class="el-card-item">
+	                    <div class="el-card-avatar el-overlay-1"> <img class="lazyload resultImages" data-src="`+bg+`">
+	                        <div class="el-overlay">
+	                            <ul class="el-info">
+	                                <li><a class="btn default btn-outline" href="javascript:void(0);" onclick="processRequest('`+v.id+`','`+v.media_type+`');"><i class="icon-link"></i>&nbsp; <span lang="en">Request</span></a></li>
+	                            </ul>
+	                        </div>
+	                    </div>
+	                    <div class="el-card-content">
+	                        <h3 class="box-title elip">`+top+`</h3> <small>`+bottom+`</small>
+	                        <br>
+						</div>
+	                </div>
+	            </div>
+	        </div>
+			`;
+		}
+
+	});
+	return results;
+}
+function processRequest(id,type){
+	if(type == 'tv'){
+		requestNewID(id).success(function(data) {
+			var newID = data.tvdb_id;
+			ombiActions(newID,'add',type);
+			console.log(id,data.tvdb_id,type);
+		}).fail(function(xhr) {
+			console.error("Organizr Function: TMDB Connection Failed");
+		});
+		console.log('tv')
+	}else{
+		ombiActions(id,'add',type);
+	}
+
+}
+function doneTyping () {
+	var title = $('#request-input').val();
+	requestSearch(title).success(function(data) {
+		//var json = JSON.parse(data);
+		console.log(data.results);
+		$('#request-results').html(buildRequestResult(data.results));
+	}).fail(function(xhr) {
+		console.error("Organizr Function: TMDB Connection Failed");
+	});
+}
 function buildDownloaderItem(array, source, type='none'){
 	var items = '';
 	switch (source) {
@@ -3122,7 +3197,18 @@ function ombiActions(id,action,type){
 	});
 	ajaxloader();
 	$.magnificPopup.close();
-	message("",window.lang.translate('Updaded Request Item'),"bottom-right","#FFF","success","3500");
+	message("",window.lang.translate('Updated Request Item'),"bottom-right","#FFF","success","3500");
+}
+//request search
+function requestSearch(title) {
+	return $.ajax({
+		url: "https://api.themoviedb.org/3/search/multi?api_key=83cf4ee97bb728eeaf9d4a54e64356a1&language="+activeInfo.language+"&query="+title+"&page=1&include_adult=true",
+	});
+}
+function requestNewID(id) {
+	return $.ajax({
+		url: "https://api.themoviedb.org/3/tv/"+id+"/external_ids?api_key=83cf4ee97bb728eeaf9d4a54e64356a1&language=en-US",
+	});
 }
 //Settings change auth
 function changeAuth(){