浏览代码

make tautulli custom names dynamic

CauseFX 4 年之前
父节点
当前提交
d0a30183bc
共有 4 个文件被更改,包括 15 次插入63 次删除
  1. 15 27
      api/homepage/plex.php
  2. 0 18
      js/custom.js
  3. 0 0
      js/custom.min.js
  4. 0 18
      js/functions.js

+ 15 - 27
api/homepage/plex.php

@@ -267,31 +267,8 @@ trait PlexHomepageItem
 					array(
 						'type' => 'switch',
 						'name' => 'homepageUseCustomStreamNames',
-						'label' => 'Use custom names for users',
+						'label' => 'Use Tautulli custom names for users',
 						'value' => $this->config['homepageUseCustomStreamNames']
-					),
-					array(
-						'type' => 'html',
-						'name' => 'grabFromTautulli',
-						'label' => 'Grab from Tautulli. (Note, you must have set the Tautulli API key already)',
-						'override' => 6,
-						'html' => '<button type="button" onclick="getTautulliFriendlyNames()" class="btn btn-sm btn-success btn-rounded waves-effect waves-light b-none">Grab Names</button>',
-					),
-					array(
-						'type' => 'html',
-						'name' => 'homepageCustomStreamNamesAce',
-						'class' => 'jsonTextarea hidden',
-						'label' => 'Custom definitions for user names (JSON Object, with the key being the plex name, and the value what you want to override with)',
-						'override' => 12,
-						'html' => '<div id="homepageCustomStreamNamesAce" style="height: 300px;">' . htmlentities($this->config['homepageCustomStreamNames']) . '</div>',
-					),
-					array(
-						'type' => 'textbox',
-						'name' => 'homepageCustomStreamNames',
-						'class' => 'jsonTextarea hidden',
-						'id' => 'homepageCustomStreamNamesText',
-						'label' => '',
-						'value' => $this->config['homepageCustomStreamNames'],
 					)
 				),
 				'Test Connection' => array(
@@ -477,6 +454,7 @@ trait PlexHomepageItem
 		if (!$this->homepageItemPermissions($this->plexHomepagePermissions('streams'), true)) {
 			return false;
 		}
+		$this->setTautulliFriendlyNames();
 		$ignore = array();
 		$exclude = explode(',', $this->config['homepagePlexStreamsExclude']);
 		$resolve = true;
@@ -848,16 +826,16 @@ trait PlexHomepageItem
 		return $plexItem;
 	}
 	
-	public function getTautulliFriendlyNames()
+	public function getTautulliFriendlyNames($bypass = null)
 	{
-		if (!$this->qualifyRequest(1)) {
+		$names = [];
+		if (!$this->qualifyRequest(1) && !$bypass) {
 			return false;
 		}
 		$url = $this->qualifyURL($this->config['tautulliURL']);
 		$url .= '/api/v2?apikey=' . $this->config['tautulliApikey'];
 		$url .= '&cmd=get_users';
 		$response = Requests::get($url, [], []);
-		$names = [];
 		try {
 			$response = json_decode($response->body, true);
 			foreach ($response['response']['data'] as $user) {
@@ -869,6 +847,16 @@ trait PlexHomepageItem
 			$this->setAPIResponse('failure', null, 422, [$e->getMessage()]);
 		}
 		$this->setAPIResponse('success', null, 200, $names);
+		return $names;
+	}
+	
+	public function setTautulliFriendlyNames()
+	{
+		if ($this->config['tautulliURL'] && $this->config['tautulliApikey'] && $this->config['homepageUseCustomStreamNames']) {
+			$names = $this->getTautulliFriendlyNames(true);
+			$this->updateConfig(array('homepageCustomStreamNames' => json_encode($names)));
+			$this->config['homepageCustomStreamNames'] = json_encode($names);
+		}
 	}
 	
 	private function formatPlexUserName($item)

+ 0 - 18
js/custom.js

@@ -1826,25 +1826,7 @@ $(document).on('click', '.close-editHomepageItemDiv',function () {
 	//$('html').removeAttr('style');
 	Custombox.modal.closeAll()
 })
-// Control init of custom plex JSON editor
-$(document).on('click', '#homepage-Plex-form li a[aria-controls="Misc Options"]', function() {
-    var resizeEditor = function(jsonEditor) {
-        const aceEditor = jsonEditor;
-        const newHeight = aceEditor.getSession().getScreenLength() * (aceEditor.renderer.lineHeight + aceEditor.renderer.scrollBar.getWidth());
-        aceEditor.container.style.height = newHeight + 'px';
-        aceEditor.resize();
-    }
 
-    jsonEditor = ace.edit("homepageCustomStreamNamesAce");
-    var JsonMode = ace.require("ace/mode/javascript").Mode;
-    jsonEditor.session.setMode(new JsonMode());
-    jsonEditor.setTheme("ace/theme/idle_fingers");
-    jsonEditor.setShowPrintMargin(false);
-    jsonEditor.session.on('change', function(delta) {
-        $('#homepageCustomStreamNamesText').val(jsonEditor.getValue());
-        $('#customize-appearance-form-save').removeClass('hidden');
-    });
-});
 // Trakt image fix
 $(document).on('click', '.get-tmdb-image', function() {
 	let target = $(this).attr('data-target');

文件差异内容过多而无法显示
+ 0 - 0
js/custom.min.js


+ 0 - 18
js/functions.js

@@ -8576,24 +8576,6 @@ function tryUpdateNetdata(array){
     });
     return existing;
 }
-function getTautulliFriendlyNames()
-{
-    organizrAPI2('GET','api/v2/homepage/tautulli/names').success(function(data) {
-        try {
-            let response = data.response;
-            if(response.data !== null){
-                var string = JSON.stringify(response.data, null, 4);
-                jsonEditor = ace.edit("homepageCustomStreamNamesAce");
-                jsonEditor.setValue(string);
-                $('#homepage-Plex-form-save').removeClass('hidden');
-            }
-        }catch(e) {
-	        organizrCatchError(e,data);
-        }
-    }).fail(function(xhr) {
-	    OrganizrApiError(xhr);
-    });
-}
 function homepageJackett(){
 	if(activeInfo.settings.homepage.options.alternateHomepageHeaders){
 		var header = `

部分文件因为文件数量过多而无法显示