Skip to content

Commit

Permalink
Update ViewMain.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
salihozkara committed Jan 14, 2023
1 parent 6c49ff6 commit 48af44a
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions src/MetricHunter.Desktop.WindowsForm/ViewMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public void ShowMessage(string message)
MessageBox.Show(message);
}

public void SetSearchProgressBar(int value)
{
value = value > 100 ? 100 : value;
value = value < 0 ? 0 : value;
_searchProgressBar.Value = value;
}

public string GithubToken => Properties.Settings.Default.GithubToken;

public IEnumerable<long> SelectedRepositories
Expand Down Expand Up @@ -61,17 +68,37 @@ public IEnumerable<SortDirection> SortDirectionSelectList
set => _sortDirectionComboBox.DataSource = value;
}

public void ShowRepositories(IEnumerable<RepositoryModel> repositories)
public void ShowRepositories(IEnumerable<Repository> repositories)
{
_repositoryDataGridView.DataSource = repositories.ToList();

if (_repositoryDataGridView.Columns["Id"] != null)
var index = 0;
var repositoryModelList = repositories.Select(x => new RepositoryModel
{
_repositoryDataGridView.Columns["Id"]!.Visible = false;
}
Id = x.Id,
Index = ++index,
Name = x.Name,
Description = x.Description,
Stars = x.StargazersCount,
Url = x.HtmlUrl,
License = x.License?.Name ?? "No License",
Owner = x.Owner.Login,
SizeString = ToSizeString(x.Size)
}).ToList();
_repositoryDataGridView.DataSource = repositoryModelList.ToList();

if (_repositoryDataGridView.Columns["Id"] != null) _repositoryDataGridView.Columns["Id"]!.Visible = false;

SetHyperLink();
}

private static string ToSizeString(long size) // size in kilobytes
{
return size switch
{
< 1024 => $"{size} KB",
< 1024 * 1024 => $"{Math.Round(size / 1024.0, 2)} MB",
_ => $"{Math.Round(size / 1024.0 / 1024.0, 2)} GB"
};
}

private void SetHyperLink()
{
Expand All @@ -94,9 +121,13 @@ private void _viewMain_Load(object sender, EventArgs e)
Presenter.LoadForm();
}

private void _searchButton_Click(object sender, EventArgs e)
private async void _searchButton_Click(object sender, EventArgs e)
{
Presenter.SearchRepositories();
SetSearchProgressBar(0);
var button = sender as Button;
button!.Enabled = false;
await Presenter.SearchRepositories();
button.Enabled = true;
}

private async void _calculateMetricsButton_Click(object sender, EventArgs e)
Expand Down

0 comments on commit 48af44a

Please sign in to comment.