@using OurUmbraco.Release
@inherits UmbracoTemplatePage
@{
    Layout = "~/Views/Master.cshtml";
    if (Request.Url != null && (Request.Url.AbsolutePath.ToLowerInvariant() == "/roadmap/" || Request.Url.AbsolutePath.ToLowerInvariant() == "/roadmap"))
    {
        var newUrl = Request.Url.AbsoluteUri.Replace("/roadmap", "/contribute/roadmap");
        Response.Redirect(newUrl, true);
    }
    var roadmap = Roadmap.GetRoadmapReleasesFromFile();
    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    var currentPage = umbracoHelper.TypedContent(umbracoHelper.UmbracoContext.PageId);
    var releaseLanding = currentPage.Parent.Children().FirstOrDefault(x => x.ContentType.Alias == "ReleaseLanding");
    var title = Model.Content.Name;
    var altHeadline = Model.Content.GetPropertyValue<string>("alternativeHeadline");
    if (string.IsNullOrWhiteSpace(altHeadline) == false)
    {
        title = altHeadline;
    }
}
<style>
    .chart canvas {
        top: -3px;
        position: absolute;
        left: -3px;
    }
</style>
<div class="subpage wrapper">
    <div>
        @Html.Action("Render", "Breadcrumb", new { linkToCurrent = false })
    </div>
    <div class="markdown-syntax">
        <h1>@title</h1>
        @Html.Raw(Model.Content.GetPropertyValue<string>("bodyText"))
        <h2>Planned Releases:</h2>
    </div>

    @foreach (var release in roadmap.OrderBy(x => x.version))
    {
        var completedIssues = release.issues.Count(x => x.state == "Fixed");
        var totalIssues = release.issues.Count();
        var percentComplete = Math.Round(((double)100 / totalIssues) * completedIssues);
        var releaseDateParsed = DateTime.Now;
        if (release.releaseDate != string.Empty)
        {
            releaseDateParsed = DateTime.Parse(release.releaseDate.Substring(3, 2) + "-" + release.releaseDate.Substring(0, 2) + "-" + release.releaseDate.Substring(6));
        }

        var releaseDate = release.releaseDate == "" ? "Not yet determined" : releaseDateParsed.ToString("dddd, MMMM d yyyy");
        IPublishedContent releaseContent = null;
        if (releaseLanding != null)
        {
            releaseContent = releaseLanding.Children().FirstOrDefault(x => string.Equals(x.Name, release.version, StringComparison.InvariantCultureIgnoreCase));
            if (releaseContent != null)
            {
                var overrideDescription = releaseContent.GetPropertyValue<bool>("overrideYouTrackDescription");
                if (overrideDescription)
                {
                    release.releaseDescription = releaseContent.GetPropertyValue<string>("bodyText");
                }
                var overrideReleaseDate = releaseContent.GetPropertyValue<string>("overrideYouTrackReleaseDate");
                if (string.IsNullOrWhiteSpace(overrideReleaseDate) == false)
                {
                    releaseDate = overrideReleaseDate;
                }

            }
        }

        <div class="releaseListing">
            <div class="plannedreleases">
                <div class="row" style="margin-top: 50px; margin-bottom: 50px;">
                    <div class="col-xs-3">
                        <span class="dot big progress">
                            <div class="chart" data-percent="@percentComplete">
                                <div class="percentage">@(percentComplete)%</div>
                            </div>
                            <span class="line v-line"></span>
                            <span class="line h-line"></span>
                        </span>
                        <span class="dot small">
                            <span class="line v-line"></span>
                            <span class="line h-line"></span>
                        </span>
                        <span class="dot small">
                            <span class="line h-line"></span>
                        </span>
                    </div>
                    <div class="col-xs-9">
                        <div class="row explain">
                            <div class="col-xs-12">
                                <h4 class="text-right"><a href="/contribute/releases/@(release.version.Replace(".",""))">v@(release.version)</a></h4>
                                @if (release.releaseDescription != string.Empty) {
                                    <small><span>@Html.Raw(release.releaseDescription)</span></small>
                                }
                            </div>
                            <div class="col-xs-6">
                                <div class="changes">
                                    <small>Features: <span>@release.issues.Count(x => x.type.ToLowerInvariant().Contains("feature"))</span></small>
                                    <small>Issues: @release.issues.Count(x => x.type.ToLowerInvariant().Contains("feature") == false && x.breaking == false)<span></span></small>
                                    <small>Breaking changes: <span>@release.issues.Count(x => x.breaking)</span></small>
                                </div>
                            </div>
                            <div class="col-xs-6">
                                <div class="changes">
                                    <small>Release date:</small>
                                    <small>@releaseDate</small>
                                </div>
                            </div>

                            <div class="col-xs-12" style="min-height: initial">
                                <h1 style="margin-top: 11px; margin-bottom: 30px; font-size: 1.4rem;">Planned features:</h1>
                            </div>
                            <div class="issues">
                                @foreach (var issue in release.issues.Where(x => x.type.ToLowerInvariant().Contains("feature")))
                                {
                                    <div class="col-sm-6" style="min-height: initial">
                                        <div class="@issue.state.Replace(" ", string.Empty)">
                                            <a href="http://issues.umbraco.org/issue/@issue.id" target="_blank"><small>@issue.id @issue.title</small></a>
                                        </div>
                                    </div>
                                }
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    }
</div>

@section EndScripts
{
    <script src="https://cdnjs.cloudflare.com/ajax/libs/easy-pie-chart/2.1.4/jquery.easypiechart.min.js"></script>
    <script type="text/javascript">
        setTimeout(function () {
            $('.chart').easyPieChart({
                size: 60,
                barColor: '#569327',
                scaleColor: false,
                trackColor: '#daf0c9'
            });
        }, 300);
    </script>
}
