<commit_before>/**
 * DataBC CITZ EDC
 *
 * HighwayThree Solutions Inc.
 * Author: <NAME> <<EMAIL>>
 *
 * MOW Modal Window
 *
**/
"use strict";

this.ckan.module('edc_mow', function($, _) {
    var self, modal, modal_subtitle, content_body, modal_controls, spinner;

    var _map = null;
    var _maxAreaHectares = null;

    var _getMaxDownloadArea = function(callbackSuccess, callbackErr) {
      _toggleSpinner(true);

      //simulate async ajax call to fetch the dataset with the maximum 
      //downloadable area for this dataset
      setTimeout(function() {
        console.log("todo: fetch the resource that gives the max downloadable area for this dataset.  for now just assume a max area of 5000000 hectares");
        _maxAreaHectares = 5000000;
        $('.max-area-hectares').html(_formatNum(_maxAreaHectares));
        callbackSuccess();
        _toggleSpinner(false);
      }, 2000);
    }

    var _mapViewChanged = function(e) {
      var bounds = _map.getBounds();
      var latLonList = [
        bounds.getSouthWest(), 
        bounds.getNorthWest(), 
        bounds.getNorthEast(), 
        bounds.getSouthEast(), 
        bounds.getSouthWest()]
      var areaM2 = L.GeometryUtil.geodesicArea(latLonList)
      var areaHect = Math.round(areaM2 * 0.0001);
      $('#selected-area').html(_formatNum(areaHect))

      if (areaHect < _maxAreaHectares) {
        //$('#order-btn').removeClass("disabled");
        $('#order-btn').prop('disabled', false);
        $('#area-warning').hide();
      }
      else {
        //$('#order-btn').addClass("disabled")
        $('#order-btn').prop('disabled', true);
        $('#area-warning').show();
      }
    }

    var _showMap = function() {

      var bcgovRoadsLayer =  
        L.tileLayer(
            'http://maps.gov.bc.ca/arcserver/rest/services/province/roads_wm/MapServer/tile/{z}/{y}/{x}', {
            attribution: '&copy; Government of British Columbia',
            minZoom: 4,
            maxZoom: 17,
            });

      var initialCenterLatLon = [53.5, -128];
      var initialZoom = 4;
      _map = L.map('map', {layers: [bcgovRoadsLayer]}) 
      
      _map.on("zoomend", _mapViewChanged)
      _map.on("moveend", _mapViewChanged)
      
      _map.setView(initialCenterLatLon, initialZoom);
    }

    var _initSuccess = function() {
      $("#mow-ready").show();
      $("#mow-err").hide();

      modal_controls.find('#order-btn').on('click', _placeOrder);

      _showMap();
    }

    var _initFailed = function() {
      $("#mow-ready").hide();
      $("#mow-err").show();
    }

    var _toggleSpinner = function(on_off) {
      spinner.toggleClass('enable', on_off);      
    }

    var _formatNum = function(x) {
      return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }

    var _placeOrder = function() {
      console.log("todo: place the order");
    }

    return {
        options: {
          // defaults
        },
        initialize: function() {
            self = this;
            modal = this.el;
            content_body = this.$('#mow-content');
            spinner = this.$('#loading');
            modal_subtitle = this.$('#modal-subtitle');
            modal_controls = this.$('.modal-footer');

            //capture the bootstrap event fired when the modal window is actually
            //shown.  
            //at this time invalidate the map to ensure it fills the expected 
            //screen real estate
            $("#edc-mow").on("shown.bs.tab", function() {
                _getMaxDownloadArea(_initSuccess, _initFailed)
            });

        },
        teardown: function() {}
    };
});
<commit_msg>added my name as an author<commit_after>/**
 * DataBC CITZ EDC
 *
 * HighwayThree Solutions Inc.
 * Author: <NAME> <<EMAIL>>, <NAME> <<EMAIL>>
 *
 * MOW Modal Window
 *
**/
"use strict";

this.ckan.module('edc_mow', function($, _) {
    var self, modal, modal_subtitle, content_body, modal_controls, spinner;

    var _map = null;
    var _maxAreaHectares = null;

    var _getMaxDownloadArea = function(callbackSuccess, callbackErr) {
      _toggleSpinner(true);

      //https://cad.data.gov.bc.ca/api/3/action/resource_show?id=6f370640-fe58-4aa9-832a-f6f615d5a335

      //simulate async ajax call to fetch the dataset with the maximum 
      //downloadable area for this dataset
      setTimeout(function() {
      

        console.log("todo: fetch the resource that gives the max downloadable area for this dataset.  for now just assume a max area of 5000000 hectares");
        _maxAreaHectares = 5000000;
        $('.max-area-hectares').html(_formatNum(_maxAreaHectares));
        callbackSuccess();
        _toggleSpinner(false);
      }, 2000);
    }

    var _mapViewChanged = function(e) {
      var bounds = _map.getBounds();
      var latLonList = [
        bounds.getSouthWest(), 
        bounds.getNorthWest(), 
        bounds.getNorthEast(), 
        bounds.getSouthEast(), 
        bounds.getSouthWest()]
      var areaM2 = L.GeometryUtil.geodesicArea(latLonList)
      var areaHect = Math.round(areaM2 * 0.0001);
      $('#selected-area').html(_formatNum(areaHect))

      if (areaHect < _maxAreaHectares) {
        //$('#order-btn').removeClass("disabled");
        $('#order-btn').prop('disabled', false);
        $('#area-warning').hide();
      }
      else {
        //$('#order-btn').addClass("disabled")
        $('#order-btn').prop('disabled', true);
        $('#area-warning').show();
      }
    }

    var _showMap = function() {

      var bcgovRoadsLayer =  
        L.tileLayer(
            'http://maps.gov.bc.ca/arcserver/rest/services/province/roads_wm/MapServer/tile/{z}/{y}/{x}', {
            attribution: '&copy; Government of British Columbia',
            minZoom: 4,
            maxZoom: 17,
            });

      var initialCenterLatLon = [53.5, -128];
      var initialZoom = 4;
      _map = L.map('map', {layers: [bcgovRoadsLayer]}) 
      
      _map.on("zoomend", _mapViewChanged)
      _map.on("moveend", _mapViewChanged)
      
      _map.setView(initialCenterLatLon, initialZoom);
    }

    var _initSuccess = function() {
      $("#mow-ready").show();
      $("#mow-err").hide();

      modal_controls.find('#order-btn').on('click', _placeOrder);

      _showMap();
    }

    var _initFailed = function() {
      $("#mow-ready").hide();
      $("#mow-err").show();
    }

    var _toggleSpinner = function(on_off) {
      spinner.toggleClass('enable', on_off);      
    }

    var _formatNum = function(x) {
      return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }

    var _placeOrder = function() {
      console.log("todo: place the order");
    }

    return {
        options: {
          // defaults
        },
        initialize: function() {
            self = this;
            modal = this.el;
            content_body = this.$('#mow-content');
            spinner = this.$('#loading');
            modal_subtitle = this.$('#modal-subtitle');
            modal_controls = this.$('.modal-footer');

            //capture the bootstrap event fired when the modal window is actually
            //shown.  
            //at this time invalidate the map to ensure it fills the expected 
            //screen real estate
            $("#edc-mow").on("shown.bs.tab", function() {
                _getMaxDownloadArea(_initSuccess, _initFailed)
            });

        },
        teardown: function() {}
    };
});

{'fraction_non_alphanumeric': 0.15258342303552205, 'fraction_numerical': 0.012782561894510226, 'mean_word_length': 2.206643658326143, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 12, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4420682', 'n_tokens_mistral': 2374, 'n_tokens_neox': 2254, 'n_words': 464}