<commit_before>import Transform from '../lib/geometry/Transform';
import Variable from "../lib/rx/Variable";
import CanvasFile from "../model/CanvasFile";
import User from "../model/User";
import * as Auth from "../Auth";

declare module gapi.drive.share {
  export var ShareClient: any;
}

export default
class CanvasFileViewModel {
  id: string;
  name = new Variable("");
  modifiedTime = new Variable(new Date());

  constructor(file: CanvasFile) {
    this.id = file.id;
    this.update(file);
  }

  update(file: CanvasFile) {
    if (this.id != file.id) {
      throw new Error("wrong file ID");
    }
    this.name.value = file.name;
    this.modifiedTime.value = file.modifiedTime;
  }

  get file() {
    return new CanvasFile({
      id: this.id,
      name: this.name.value,
      modifiedTime: this.modifiedTime.value
    });
  }

  async rename(name: string) {
    this.name.value = name;
    await CanvasFile.rename(this.id, name);
  }

  dispose() {
  }

  async openShareDialog() {
    const shareClient = new gapi.drive.share.ShareClient();
    shareClient.setOAuthToken(Auth.accessToken);
    shareClient.setItemIds([this.id]);
    shareClient.showSettingsDialog();
  }
}<commit_msg>Send rename request only if needed<commit_after>import Transform from '../lib/geometry/Transform';
import Variable from "../lib/rx/Variable";
import CanvasFile from "../model/CanvasFile";
import User from "../model/User";
import * as Auth from "../Auth";

declare module gapi.drive.share {
  export var ShareClient: any;
}

export default
class CanvasFileViewModel {
  id: string;
  name = new Variable("");
  modifiedTime = new Variable(new Date());

  constructor(file: CanvasFile) {
    this.id = file.id;
    this.update(file);
  }

  update(file: CanvasFile) {
    if (this.id != file.id) {
      throw new Error("wrong file ID");
    }
    this.name.value = file.name;
    this.modifiedTime.value = file.modifiedTime;
  }

  get file() {
    return new CanvasFile({
      id: this.id,
      name: this.name.value,
      modifiedTime: this.modifiedTime.value
    });
  }

  async rename(name: string) {
    if (this.name.value != name) {
      this.name.value = name;
      await CanvasFile.rename(this.id, name);
    }
  }

  dispose() {
  }

  async openShareDialog() {
    const shareClient = new gapi.drive.share.ShareClient();
    shareClient.setOAuthToken(Auth.accessToken);
    shareClient.setItemIds([this.id]);
    shareClient.showSettingsDialog();
  }
}
{'fraction_non_alphanumeric': 0.13927125506072874, 'fraction_numerical': 0.0, 'mean_word_length': 3.118333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6523427', 'n_tokens_mistral': 805, 'n_tokens_neox': 780, 'n_words': 186}