# frozen_string_literal: true class ProjectsController < ApplicationController before_action :ignore_request_format, only: [:show] LANGUAGES = { "C#": { start_date: "2017-01-01", end_date: "2019-02-01", color: "#9374b9", projects: %w[ esm_alpha csharp_projects esm_arma_v1 arcas_dev_tools_csharp ] }, Java: { start_date: "2016-01-01", end_date: "2018-01-01", color: "#4677be", projects: %w[ java_projects ] }, JavaScript: { start_date: "2016-05-01", end_date: "", color: "#bfa043", projects: %w[ esm_alpha esm_bot_v1 itsthedevman ] }, PHP: { start_date: "2017-06-01", end_date: "2018-02-01", color: "#7761a0", projects: %w[ esm_alpha ] }, Python: { start_date: "2015-10-01", end_date: "2018-01-01", color: "#be9f4a", projects: %w[ python_projects ] }, Ruby: { start_date: "2018-05-01", end_date: "", color: "#ae5a62", projects: %w[ esm_bot esm_website itsthedevman redis_ipc ] }, Rust: { start_date: "2020-08-01", end_date: "", color: "#be7f4a", projects: %w[ esm_arma ] }, SQF: { start_date: "2014-10-01", end_date: "", color: "#414749", projects: %w[ esm_alpha esm_arma_v1 esm_arma marxet_v1 marxet_v2 arcas_dev_tools ] }, SQL: { start_date: "2015-12-01", end_date: "", color: "#31648c", projects: %w[ esm_alpha esm_arma_v1 esm_arma esm_website esm_bot itsthedevman ] }, TypeScript: { start_date: "2024-03-01", end_date: "", color: "#46a5b8", projects: %w[ itsthedevman ] } }.symbolize_keys.freeze LANGUAGE_DISPLAY_ORDER = %i[ C# Java JavaScript PHP Python Ruby Rust SQF SQL TypeScript ] def index authorize :project all_languages = LANGUAGE_DISPLAY_ORDER.map do |name| color = LANGUAGES[name][:color] {name:, color:} end render locals: { timeline: build_language_timeline, all_languages: } end def show current_project = authorize Project.find_by(public_id: params[:id]) entry_cache = current_project.entries # if (filter_id = params[:filter]) # filter = current_project.filters.find_by(public_id: filter_id) # entry_cache = entry_cache.with_filter(filter) if filter # end file_path = params[:file_path] || "README.md" current_entry = entry_cache.find_by_path(file_path) render locals: { current_project:, current_entry: } end private def ignore_request_format request.format = :html end def build_language_timeline all_projects = Project.all.index_by(&:public_id) timeline = Hash.new { |hash, key| hash[key] = Set.new } LANGUAGES.each do |language, data| language = Project::Language.from(language, **data) language.active_years.each do |year| timeline[year].add( language.with( # Only grab the languages that were active during this year projects: active_projects_for_year(all_projects, language, year) ) ) end end timeline.transform_values { |l| l.index_by(&:name) } # Reverse the order so the latest year is at the top .sort { |(year_a, _projects_a), (year_b, _projects_b)| year_b <=> year_a } .to_h end def active_projects_for_year(all_projects, language, year) language.projects.filter_map do |name| project = all_projects[name] next unless project&.active_years&.include?(year) ProjectPresenter.new(project, language.color).with_context(self) end end end