Jump to content

GenericListItem -> ToggleButton ->


Recommended Posts

Posted

@softworkzI have a nested GenericListItem and I have a toggle button on it, when I press the toggle button it tells me "Command is not implemented", whats going on here. It looks like the logs show it hitting the IsCommandAllowed 2x as I see my log message.

 

2024-12-06 13:03:28.962 Info Emby Media Items Not Matched: Command Key is ToggleAssociateMedia
2024-12-06 13:03:28.965 Info Emby Media Items Not Matched: Command Key is ToggleAssociateMedia
2024-12-06 13:03:28.967 Error Server: Error processing request
    *** Error Report ***
    Version: 4.9.0.30
    Command line: /app/emby/system/EmbyServer.dll -programdata /config -ffdetect /app/emby/bin/ffdetect -ffmpeg /app/emby/bin/ffmpeg -ffprobe /app/emby/bin/ffprobe -restartexitcode 3
    Operating system: Linux version 6.7.12+bpo-amd64 (debian-kernel@lists.debian.org) (x86_64-linux-gnu-gcc-12 (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2
    OS/Process: x64/x64
    Framework: .NET 8.0.6
    Runtime: app/emby/system/System.Private.CoreLib.dll
    Processor count: 4
    Data path: /config
    Application path: /app/emby/system
    MediaBrowser.Model.Plugins.UI.EmbyUserException: MediaBrowser.Model.Plugins.UI.EmbyUserException: Command is not implemented
       at Emby.Web.GenericUI.Control.PageHosts.PageControllerHostBase.RunCommand(String requestItemId, String requestCommandId, String requestData, UserDto user)
       at Emby.Web.GenericUI.Api.GenericUIApiService.Post(RunUICommand request)
       at Emby.Server.Implementations.Services.ServiceController.GetTaskResult(Task task)
       at Emby.Server.Implementations.Services.ServiceHandler.ProcessRequestAsync(HttpListenerHost httpHost, IServerApplicationHost appHost, IRequest httpReq, IResponse httpRes, IStreamHelper streamHelper, RestPath restPath, String responseContentType, CancellationToken cancellationToken)
       at Emby.Server.Implementations.HttpServer.HttpListenerHost.RequestHandler(IRequest httpReq, ReadOnlyMemory`1 urlString, ReadOnlyMemory`1 localPath, CancellationToken cancellationToken)
    Source: Emby.Web.GenericUI
    TargetSite: Void MoveNext()

 

new GenericListItem
                                 {
                                     Icon        = IconNames.video_file,
                                     PrimaryText = baseItem.Name,
                                     SecondaryText =
                                         $"{baseItem.ProductionYear} :: {library.LibraryOptions.ContentType} :: {baseItem.Path}",
                                     SubItems = subItems,
                                     Toggle = new ToggleButtonItem
                                              {
                                                  Caption = "Associate Media",
                                                  IsChecked = filteredSearchItem.Score >=
                                                      PluginUiOptions.ConfidenceScore,
                                                  Data1 = "ToggleAssociateMedia",
                                                  Data2 =
                                                      _jsonSerializer
                                                          .SerializeToString(fileToMatch)
                                              }
                                 }

 

public override bool IsCommandAllowed(string commandKey)
{
    _logger.Info($"Command Key is {commandKey}");

    return commandKey switch
           {
               "SearchMissing" => true,
               "MatchMissing" => true,
               "ToggleAssociateMedia" => true,
               _ => base.IsCommandAllowed(commandKey)
           };
}


public override async Task<IPluginUIView> RunCommand(string itemId, string commandId, string data)
{
    if (commandId == "ToggleAssociateMedia")
    {
        var toggleData = 
            _jsonSerializer.DeserializeFromString(data, typeof(FileToMatch)) as
                FileToMatch;

        if (_filesToMatch.Find(x => x.Id == toggleData.Id).Equals(true))
        {
            _filesToMatch.Remove(_filesToMatch.Find(x => x.Id == toggleData.Id));
        }
        
        _filesToMatch.Add(toggleData);
    }
}
Posted

You need to return 'this' in the RunComand() method, so that it doesn't run into the base class implementation.

Posted

If you wonder why to return 'this': What you return here is the next view to display, for example you could return a dialog to show a dialog. Returning this means that it remains on the same view.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...