~hristoast/mousikofidi

703bfaa81128fe058916f3d430e6e184771e4160 — Hristos N. Triantafillou 1 year, 11 months ago 6bfb45c
Navigate to the former dir's position with breadcrumb links (#111)
M mousikofidi/mousikofidi.py => mousikofidi/mousikofidi.py +14 -6
@@ 710,8 710,9 @@ def breadcrumb_links_from_path(path: str, music_dirs: list) -> str:
    for d in music_dirs:
        if path.startswith(d):
            _path = d.strip("/")
            link_string += '<a href="{url}">{path}</a>'.format(
                url=url_for(".dir_detail", path=_path), path=d
            eid = path.split(os.path.sep)[-1]
            link_string += '<a href="{url}?goto={eid}">{path}</a>'.format(
                url=url_for(".dir_detail", path=_path), path=d, eid=eid
            )
            path_string += d
            new_path = path.replace(d, "").strip("/")


@@ 721,10 722,17 @@ def breadcrumb_links_from_path(path: str, music_dirs: list) -> str:
                if dd:
                    path_string = os.path.join(path_string, dd)
                    if os.path.isdir(path_string):
                        link_string += ' / <a href="{url}">{name}</a>'.format(
                            name=dd,
                            url=url_for(".dir_detail", path=path_string.strip("/")),
                        )
                        if dd == dir_list[-1]:
                            link_string += ' / <a href="{url}">{name}</a>'.format(
                                name=dd,
                                url=url_for(".dir_detail", path=path_string.strip("/")),
                            )
                        else:
                            link_string += ' / <a href="{url}?goto={eid}">{name}</a>'.format(
                                eid=dir_list[-1].split(os.path.sep)[-1],
                                name=dd,
                                url=url_for(".dir_detail", path=path_string.strip("/")),
                            )
                    elif os.path.isfile(path_string):
                        link_string += " / {}".format(dd)
    return link_string

M mousikofidi/static/css/fidi.css => mousikofidi/static/css/fidi.css +5 -0
@@ 307,6 307,11 @@ div.anchor {
    position: relative;
}

div.dir-anchor {
    bottom: 60px;
    position: relative;
}

div.play-arrow, div.video-arrow {
    width: 0;
    height: 0;

M mousikofidi/static/js/player.js => mousikofidi/static/js/player.js +3 -0
@@ 1088,6 1088,9 @@ function FidiPlayerSetUp() {
    if (videoLinkButton)
        videoLinkButton.addEventListener("click", videoLinkListener);

    if (params.has("goto"))
        document.getElementById(params.get("goto")).scrollIntoView({behavior: "smooth"});

    if (params.has("t"))
        seekTrack();


M mousikofidi/templates/dir_table.html => mousikofidi/templates/dir_table.html +1 -0
@@ 10,6 10,7 @@
      {% for dir in dir_list %}
        <tr>
          <td>
            <div class="dir-anchor" id="{{ dir.path.split('/')[-1] }}"></div>
            <a class="bold mobile-big" href="{{ url_for('.dir_detail', path=dir.path) }}">
              {% if icons %}<i class="fas fa-folder"></i> {% endif %}{{ dir.name }}
            </a>

M test_mousikofidi.py => test_mousikofidi.py +8 -5
@@ 199,13 199,16 @@ def test_breadcrumb_links_from_path_dir():
    # TODO: somehow use url_for() here;
    # RuntimeError: Attempted to generate a URL without the application context being pushed. This has to be executed when application context is available.
    dir_detail_url = "/browse/{}".format(example_dir.strip("/"))
    expected_string = '<a href="{url}">{full_path}</a>'.format(
    expected_string = '<a href="{url}?goto=example">{full_path}</a>'.format(
        full_path=example_dir, url=dir_detail_url
    )

    with app.test_request_context(dir_detail_url):
        link_string = breadcrumb_links_from_path(example_dir, [example_dir])

    print(link_string)
    print(expected_string)

    assert link_string == expected_string




@@ 213,7 216,7 @@ def test_breadcrumb_links_from_path_file():
    example_dir = os.path.join(THIS_DIR, "example")
    file_path = os.path.join(example_dir, "real.flac")
    url = "/browse/{}".format(example_dir.strip("/"))
    expected_string = '<a href="{url}">{path}</a> / real.flac'.format(
    expected_string = '<a href="{url}?goto=real.flac">{path}</a> / real.flac'.format(
        path=example_dir, url=url
    )



@@ 228,7 231,7 @@ def test_breadcrumb_links_from_path_deep_dir():
    base = os.path.join(tmpdir, "flac")
    tmpdeep = os.path.join(base, "SomeArtist", "SomeAlbum", "SomeDisc")
    os.makedirs(tmpdeep)
    expected_string = '<a href="{url1}">{dir1}</a> / <a href="{url2}">{dir2}</a> / <a href="{url3}">{dir3}</a> / <a href="{url4}">{dir4}</a>'.format(
    expected_string = '<a href="{url1}?goto=SomeDisc">{dir1}</a> / <a href="{url2}?goto=SomeDisc">{dir2}</a> / <a href="{url3}?goto=SomeDisc">{dir3}</a> / <a href="{url4}">{dir4}</a>'.format(
        dir1=os.path.join(tmpdir, "flac"),
        dir2="SomeArtist",
        dir3="SomeAlbum",


@@ 254,7 257,7 @@ def test_breadcrumb_links_from_path_deep_file():
    tmpdeep = os.path.join(base, "SomeArtist", "SomeAlbum", "SomeDisc")
    os.makedirs(tmpdeep)

    expected_string = '<a href="{url1}">{dir1}</a> / <a href="{url2}">{dir2}</a> / <a href="{url3}">{dir3}</a> / <a href="{url4}">{dir4}</a> / real.flac'.format(
    expected_string = '<a href="{url1}?goto=real.flac">{dir1}</a> / <a href="{url2}?goto=real.flac">{dir2}</a> / <a href="{url3}?goto=real.flac">{dir3}</a> / <a href="{url4}?goto=real.flac">{dir4}</a> / real.flac'.format(
        dir1=os.path.join(tmpdir, "flac"),
        dir2="SomeArtist",
        dir3="SomeAlbum",


@@ 1630,7 1633,7 @@ def test_dir_detail_found(client):
    )
    assert (
        bytes(
            '<h4 class="center mobile-big"><a href="/browse/{0}">{1}</a></h4>'.format(
            '<h4 class="center mobile-big"><a href="/browse/{0}?goto=example">{1}</a></h4>'.format(
                example_dir.strip("/"), example_dir
            ),
            "utf8",