PlaylistTableItem.razor 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. @using Newtonsoft.Json
  2. @using System.Runtime.InteropServices.JavaScript
  3. @inherits FnzComponentBase
  4. @code {
  5. [Parameter, Required] public Guid PlaylistId { get; set; }
  6. [Parameter, Required] public int TrackCount { get; set; }
  7. [Parameter, Required] public int TrackIndex { get; set; }
  8. [Parameter, Required] public FeTrack Track { get; set; }
  9. private DiscDialog dlgDisc;
  10. protected override async Task OnAfterRenderAsync(bool firstRender)
  11. {
  12. await base.OnAfterRenderAsync(firstRender);
  13. await JSRuntime.InvokeVoidAsync(Prefix + ".initDragSource", ElementId, DotNetRef, FnzConst.DragDropTypePlaylistItem);
  14. await JSRuntime.InvokeVoidAsync(Prefix + ".initDropZone", ElementId, DotNetRef, FnzConst.DragDropTypePlaylistItem);
  15. }
  16. private async Task EnableDragDrop() => await JSRuntime.InvokeVoidAsync(Prefix + ".setDraggableOn", ElementId);
  17. private async Task DisableDragDrop() => await JSRuntime.InvokeVoidAsync(Prefix + ".setDraggableOff", ElementId);
  18. [JSInvokable("FnzDragStartProvideContent")]
  19. public string FnzDragStartProvideContent(string dataType)
  20. {
  21. if (dataType != FnzConst.DragDropTypePlaylistItem) return null;
  22. var ds = new PlaylistDragSource { PlaylistId = PlaylistId, TrackIndex = TrackIndex, Path = Track.Path };
  23. var str = JsonConvert.SerializeObject(ds);
  24. return str;
  25. }
  26. [JSInvokable("FnzDragDropContent")]
  27. public void FnzDragDropContent(string dataType, string c)
  28. {
  29. if (dataType != FnzConst.DragDropTypePlaylistItem) return;
  30. var ds = JsonConvert.DeserializeObject<PlaylistDragSource>(c);
  31. if (ds == null || ds.Path == null || string.IsNullOrWhiteSpace(ds.Path)) return;
  32. PlaylistHelper.TrackMove(ds.PlaylistId, ds.TrackIndex, ds.Path, PlaylistId, TrackIndex);
  33. }
  34. }
  35. <tr id="@ElementId" class="mouse-hilight" @ondragend="DisableDragDrop">
  36. <td colspan="2" style="width:0">
  37. <img src="@Track.Disc.CoverPath" style="height:50px" @onclick="()=>dlgDisc.Show(Track.Disc)" />
  38. <DiscDialog @ref="dlgDisc"></DiscDialog>
  39. </td>
  40. <td class="align-middle" style="width:250px">
  41. <FileIcon Track="@Track" ShowParam="true"></FileIcon>
  42. </td>
  43. <td colspan="1" class="align-top w-100">
  44. <div class="text-nowrap">
  45. <a @onclick="() => App.Instance.PlayTrack(Track)" @onclick:preventDefault href="@Track.Path" target="@FnzConst.PlayPageTarget">
  46. @Track.GetTitleOrFilename()
  47. </a>
  48. </div>
  49. <div class="text-nowrap text-muted"> @Track.Tag?.Artist</div>
  50. </td>
  51. <td>
  52. <div class="dropend">
  53. <div id="@(ElementId)-handle" data-bs-toggle="dropdown" class="p-2 border border-primary" style="cursor: move" @onmousedown="EnableDragDrop" @onmouseup="DisableDragDrop">
  54. <i class="bi bi-list"></i>
  55. </div>
  56. @if (TrackCount > 1)
  57. {
  58. var isFirst = TrackIndex == 0;
  59. var isLast = TrackIndex == TrackCount - 1;
  60. <div class="dropdown-menu text-end p-1 text-nowrap" style="width: initial;min-width: initial;">
  61. <button class="btn btn-primary p-2" disabled="@isFirst" @onclick="()=>PlaylistHelper.TrackMoveUp(PlaylistId,TrackIndex)">
  62. <i class="bi bi-arrow-bar-up"></i>
  63. Up
  64. </button>
  65. <button class="btn btn-primary p-2" disabled="@isLast" @onclick="()=>PlaylistHelper.TrackMoveDown(PlaylistId,TrackIndex)">
  66. <i class="bi bi-arrow-bar-down"></i>
  67. Down
  68. </button>
  69. </div>
  70. }
  71. </div>
  72. </td>
  73. <td class="text-center" colspan="2">
  74. <div class="text-nowrap">@Track.Tag?.Duration.SecondToDur()</div>
  75. <div class="text-nowrap text-muted"> @Track.Tag?.Length.BytesToFileSize()</div>
  76. </td>
  77. <td>
  78. <div class="dropstart">
  79. <button type="button" class="btn btn-danger p-2" data-bs-toggle="dropdown">
  80. <i class="bi bi-folder-minus"></i>
  81. </button>
  82. <ul class="dropdown-menu mx-2">
  83. <li><button class="dropdown-item text-danger" @onclick="()=>PlaylistHelper.RemoveTrackInPlaylist(PlaylistId,TrackIndex,Track.Path)">Confirm Remove</button></li>
  84. </ul>
  85. </div>
  86. </td>
  87. </tr>