<link href="<?=base_url()?>assets/css/plugins/codemirror/codemirror.css" rel="stylesheet">
<link href="<?=base_url()?>assets/css/plugins/codemirror/ambiance.css" rel="stylesheet">
<div class="wrapper wrapper-content animated fadeIn">
	<div class="row">
      <div class="col-lg-12">
          <div class="tabs-container">
              <ul class="nav nav-tabs">
                  <li class="active"><a data-toggle="tab" href="#tab-10">
                      Update GIT <i class="fa fa-github"></i>
                  </a>
                  </li>
              </ul>
              <div class="tab-content">
                  <div id="tab-10" class="tab-pane active">
                      <div class="panel-body">
											<button class="btn btn-primary updateGitButton" type="submit">Update Source</button>
													<strong> Click to update the code from GIT repository</strong>
											<button class="btn btn-primary logGitButton pull-right" type="submit">Update Log</button>
											<div class="col-sm-1 pull-right">
												<select class="chosen-select " name="log_size" id="log_size">
	                          <option selected>10</option>
	                          <option>20</option>
	                          <option>30</option>
	                          <option value="">ALL</option>
	                      </select>
											</div>
													<div class="hr-line-dashed"></div>
<textarea id="code1" readonly>
// result wil show in here
</textarea>
                      </div>
                  </div>
              </div>
          </div>
      </div>
  </div>
</div>
<!-- CodeMirror -->
<script src="<?=base_url()?>assets/js/plugins/codemirror/codemirror.js"></script>
<script src="<?=base_url()?>assets/js/plugins/codemirror/mode/javascript/javascript.js"></script>
<script>
	var result_code = CodeMirror.fromTextArea(document.getElementById("code1"), {
	   lineNumbers: true,
	   matchBrackets: true,
	   styleActiveLine: true,
	   readOnly: true,
	   theme:"ambiance"
	});
	var updateGitButton = $('.updateGitButton').ladda();
	var logGitButton = $('.logGitButton').ladda();
	updateGitButton.click(function() {
			let btn = $(this);
			startLoadingButton(btn);
			swal.fire({
				title: "Ambil update dari server?",
				text: "Aplikasi akan di update",
				icon: "warning",
				showCancelButton: true,
				confirmButtonText: 'Get Update',
			}).then(isConfirm => {
				if (isConfirm.value) {
					$.ajax({
						type: "POST",
						url: site_url + "hooks/gitPull",
						dataType: 'json',
						success: function(response) {
							var result_text = '';
							response.forEach(function(res){
								result_text = result_text+res+'\n';
							});
							result_code.setValue(result_text);
							stopLoadingButton(btn);
						},
						error: function(jqXhr, textStatus, errorThrown) {
							var error_message = 'internal error';
							if (jqXhr.responseJSON !== undefined) {
								error_message = jqXhr['responseJSON']['message'];
							}
							swal.fire('error', error_message, "error");
							stopLoadingButton(btn);
						}
					});
				} else {
					stopLoadingButton(btn);
					return false;
				}
			});
		});
	logGitButton.click(function() {
			let btn = $(this);
			startLoadingButton(btn);
			$.ajax({
				type: "POST",
				url: site_url + "hooks/gitLog",
				dataType: 'json',
				data: {
					log_size : $('#log_size').val()
				},
				success: function(response) {
					var result_text = '';
					response.forEach(function(res){
						result_text = result_text+res+'\n';
					});
					result_code.setValue(result_text);
					stopLoadingButton(btn);
				},
				error: function(jqXhr, textStatus, errorThrown) {
					var error_message = 'internal error';
					if (jqXhr.responseJSON !== undefined) {
						error_message = jqXhr['responseJSON']['message'];
					}
					swal.fire('error', error_message, "error");
					stopLoadingButton(btn);
				}
			});
		});
</script>