<commit_before>#------------------------------------------------------------------------------
#
# MaintenanceUpdatesTemplateBuilder
#
# Creates a template for capturing maintenance updates for existing inventory
#
#------------------------------------------------------------------------------
class MaintenanceUpdatesTemplateBuilder < TemplateBuilder

  SHEET_NAME = MaintenanceUpdatesFileHandler::SHEET_NAME

  protected

  # Add a row for each of the asset for the org
  def add_rows(sheet)
    @asset_types.each do |asset_type|
      assets = @organization.assets.operational.where('asset_type_id = ?', asset_type)
      assets.each do |a|
        asset = Asset.get_typed_asset(a)
        row_data  = []
        row_data << asset.object_key
        row_data << asset.asset_type.name
        row_data << asset.asset_subtype.name
        row_data << asset.asset_tag
        row_data << asset.external_id
        row_data << asset.description

        if a.type_of? :maintenance_vehicle and a.maintenance_updates.present?
          event = a.maintenance_updates.last
          row_data << event.maintenance_type.name
          row_data << event.current_mileage
          row_data << event.event_date
        else
          row_data << nil # current_maintenance type
          row_data << nil # current mileage
          row_data << nil # reprot date
        end
        row_data << nil # current_maintenance type
        row_data << nil # current mileage
        row_data << nil # report date
        row_data << nil # notes

        sheet.add_row row_data, :types => row_types
      end
    end
    # Do nothing
  end

  # Configure any other implementation specific options for the workbook
  # such as lookup table worksheets etc.
  def setup_workbook(workbook)

    # Add a lookup table worksheet and add the lookuptable values we need to it
    sheet = workbook.add_worksheet :name => 'lists', :state => :very_hidden
    sheet.sheet_protection.password = '<PASSWORD>'

    row = []
    @maintenance_types = MaintenanceType.active.pluck(:name)
    @maintenance_types.each do |x|
      row << x unless x.eql? "Unknown"
    end
    sheet.add_row row

  end

  # Performing post-processing
  def post_process(sheet)

    # Merge Cells?
    sheet.merge_cells("A1:F1")
    sheet.merge_cells("G1:M1")

    # This is used to get the column name of a lookup table based on its length
    alphabet = ('A'..'Z').to_a
    earliest_date = SystemConfig.instance.epoch

    # Maintenance Type
    sheet.add_data_validation("J3:J1000", {
      :type => :list,
      :formula1 => "lists!$A$1:$#{<EMAIL>]}$1",
      :allow_blank => true,
      :showErrorMessage => true,
      :errorTitle => 'Wrong input',
      :error => 'Select a value from the list',
      :errorStyle => :information,
      :showInputMessage => true,
      :promptTitle => 'Maintenance type',
      :prompt => 'Only values in the list are allowed'})

    # Milage -Integer > 0
    sheet.add_data_validation("K2:K1000", {
      :type => :whole,
      :operator => :greaterThan,
      :allow_blank => true,
      :showErrorMessage => true,
      :errorTitle => 'Wrong input',
      :error => 'Milage must be > 0',
      :errorStyle => :information,
      :showInputMessage => true,
      :promptTitle => 'Current mileage',
      :prompt => 'Only values greater than 0'})

    # Maintenance Date
    sheet.add_data_validation("L3:L1000", {
      :type => :time,
      :operator => :greaterThan,
      :formula1 => earliest_date.strftime("%-m/%d/%Y"),
      :allow_blank => true,
      :errorTitle => 'Wrong input',
      :error => "Date must be after #{earliest_date.strftime("%-m/%d/%Y")}",
      :errorStyle => :information,
      :showInputMessage => true,<commit_msg>lock maintenance updates template [#115447497]<commit_after>#------------------------------------------------------------------------------
#
# MaintenanceUpdatesTemplateBuilder
#
# Creates a template for capturing maintenance updates for existing inventory
#
#------------------------------------------------------------------------------
class MaintenanceUpdatesTemplateBuilder < TemplateBuilder

  SHEET_NAME = MaintenanceUpdatesFileHandler::SHEET_NAME

  protected

  # Add a row for each of the asset for the org
  def add_rows(sheet)
    @asset_types.each do |asset_type|
      assets = @organization.assets.operational.where('asset_type_id = ?', asset_type)
      assets.each do |a|
        asset = Asset.get_typed_asset(a)
        row_data  = []
        row_data << asset.object_key
        row_data << asset.asset_type.name
        row_data << asset.asset_subtype.name
        row_data << asset.asset_tag
        row_data << asset.external_id
        row_data << asset.description

        if a.type_of? :maintenance_vehicle and a.maintenance_updates.present?
          event = a.maintenance_updates.last
          row_data << event.maintenance_type.name
          row_data << event.current_mileage
          row_data << event.event_date
        else
          row_data << nil # current_maintenance type
          row_data << nil # current mileage
          row_data << nil # reprot date
        end
        row_data << nil # current_maintenance type
        row_data << nil # current mileage
        row_data << nil # report date
        row_data << nil # notes

        sheet.add_row row_data, :types => row_types
      end
    end
    # Do nothing
  end

  # Configure any other implementation specific options for the workbook
  # such as lookup table worksheets etc.
  def setup_workbook(workbook)

    # Add a lookup table worksheet and add the lookuptable values we need to it
    sheet = workbook.add_worksheet :name => 'lists', :state => :very_hidden
    sheet.sheet_protection.password = '<PASSWORD>'

    row = []
    @maintenance_types = MaintenanceType.active.pluck(:name)
    @maintenance_types.each do |x|
      row << x unless x.eql? "Unknown"
    end
    sheet.add_row row

  end

  # Performing post-processing
  def post_process(sheet)

    # protect sheet so you cannot update cells that are locked
    sheet.sheet_protection

    # Merge Cells?
    sheet.merge_cells("A1:F1")
    sheet.merge_cells("G1:M1")

    # This is used to get the column name of a lookup table based on its length
    alphabet = ('A'..'Z').to_a
    earliest_date = SystemConfig.instance.epoch

    # Maintenance Type
    sheet.add_data_validation("J3:J1000", {
      :type => :list,
      :formula1 => "lists!$A$1:$#{<EMAIL>]}$1",
      :allow_blank => true,
      :showErrorMessage => true,
      :errorTitle => 'Wrong input',
      :error => 'Select a value from the list',
      :errorStyle => :stop,
      :showInputMessage => true,
      :promptTitle => 'Maintenance type',
      :prompt => 'Only values in the list are allowed'})

    # Milage -Integer > 0
    sheet.add_data_validation("K2:K1000", {
      :type => :whole,
      :operator => :greaterThan,
      :allow_blank => true,
      :showErrorMessage => true,
      :errorTitle => 'Wrong input',
      :error => 'Milage must be > 0',
      :errorStyle => :stop,
      :showInputMessage => true,
      :promptTitle => 'Current mileage',
      :prompt => 'Only values greater than 0'})

    # Maintenance Date
    sheet.add_data_validation("L3:L1000", {
      :type => :time,
      :operator => :greaterThan,
      :formula1 => earliest_date.strftime("%-m/%d/%Y"),
      :allow_blank => true,
      :errorTitle => 'Wrong input',
      :error => "Date must be after #{earliest_date.strftime("%-m/%d/%Y")}",
      :errorStyle => :stop,
      :showInputMessage => true,
{'fraction_non_alphanumeric': 0.14640920513159636, 'fraction_numerical': 0.008067715910593836, 'mean_word_length': 2.3895114298520843, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6537972', 'n_tokens_mistral': 2285, 'n_tokens_neox': 2171, 'n_words': 577}