<commit_before>var http = require('http');
var fs = require('fs');
var os = require('os');

var options = {
    host: '127.0.0.1',
    port: 8000,
    path: '/api/system',
    method: 'GET',
    headers: {
        'Accept': 'text/json'
    }
};

var apiSystem = {};
var responseJson = 'api_system.json';

function sendHttpRequest(opts) {
    var req = http.request(opts, function(res) {
        apiSystem.statusCode = res.statusCode;
        res.setEncoding('utf8');

        res.on('data', function(data) {
            apiSystem.apiResponse = JSON.parse(data);
               fs.writeFileSync(responseJson, JSON.stringify(apiSystem));
        });
    });
    req.end();
}

// First generate HTTP response file. Only node script will generate the
// json format response.
if (process.argv[1] == __filename) {
    sendHttpRequest(options);
}

module.exports = {
    setUp: function(callback) {
        var content = fs.readFileSync(responseJson);
        this.apiSystem = JSON.parse(content.toString());

        callback();
    },
    tearDown: function(callback) {
        callback();
    },

    // statue code
    testApiSystemStatusCode: function(test) {
        test.strictEqual(this.apiSystem.statusCode, 200,
                        'Response is not OK!');
        test.done();
    },

    // hostname
    testApiSystemHostnameNotNull: function(test) {
        test.ok('hostname' in this.apiSystem.apiResponse,
                    'hostname is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemHostnameType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['hostname'], 'string',
                        'hostname property is not string!');
        test.done();
    },
    testApiSystemHostnameValue: function(test) {
        test.strictEqual(this.apiSystem.apiResponse['hostname'], os.hostname(),
                        'local hostname value differs from the one from api response!');
        test.done();
    },

    // type
    testApiSystemTypeNotNull: function(test) {
        test.ok('type' in this.apiSystem.apiResponse,
                    'type is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemTypeType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['type'], 'string',
                        'type property is not string!');
        test.done();
    },
    testApiSystemTypeValue: function(test) {
        test.strictEqual(this.apiSystem.apiResponse['type'], os.type(),
                        'local type value differs from the one from api response!');
        test.done();
    },

    // arch
    testApiSystemArchNotNull: function(test) {
        test.ok('arch' in this.apiSystem.apiResponse,
                    'arch is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemArchType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['arch'], 'string',
                    'arch property is not string!');
        test.done();
    },
    testApiSystemArchValue: function (test) {
        test.strictEqual(this.apiSystem.apiResponse['arch'], os.arch(),
                        'local arch value differs from the one from /api/system!');
        test.done();
    },

    // release
    testApiSystemReleaseNotNull: function(test) {
        test.ok('release' in this.apiSystem.apiResponse,
                    'release is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemReleaseType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['release'], 'string',
                    'release property is not a string!');
        test.done();
    },
    testApiSystemReleaseValue: function (test) {
        test.strictEqual(this.apiSystem.apiResponse['release'], os.release(),
                        'local release value differs from the one from /api/system!');
        test.done();
    },

    // uptime
    testApiSystemUptimeNotNull: function(test) {
        test.ok('uptime' in this.apiSystem.apiResponse,
                    'uptime is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemUptimeType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['uptime'], 'number',
                    'uptime property is not a number!');
        test.done();
    },

    // loadavg
    testApiSystemLoadavgNotNull: function(test) {
        test.ok('loadavg' in this.apiSystem.apiResponse,
                    'loadavg is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemLoadavgType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['loadavg'], 'object',
                    'loadavg property is not an array!');

        for (var i = 0; i < this.apiSystem.apiResponse['loadavg'].length; i++) {
            test.strictEqual(typeof this.apiSystem.apiResponse['loadavg'][i], 'number',
                            'some item in loadavg property is not a number!');
        }
        test.done();
    },

    // totalmem
    testApiSystemTotalmemNotNull: function(test) {
        test.ok('totalmem' in this.apiSystem.apiResponse,
                    'totalmem is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemTotalmemType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['totalmem'], 'number',
                    'totalmem property is not a string!');
        test.done();
    },
    testApiSystemTotalmemValue: function (test) {
        test.strictEqual(this.apiSystem.apiResponse['totalmem'], os.totalmem(),
                        'local totalmem value differs from the one from /api/system!');
        test.done();
    },

    // freemem
    testApiSystemFreememNotNull: function(test) {
        test.ok('freemem' in this.apiSystem.apiResponse,
                    'freemem is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemFreememType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['freemem'], 'number',
                    'freemem property is not a string!');
        test.done();
    },

    // cpus
    testApiSystemCpusNotNull: function(test) {
        test.ok('cpus' in this.apiSystem.apiResponse,
                    'cpus is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemCpusType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['cpus'], 'object',
                    'cpus property is not an array!');
        test.done();
    },
    testApiSystemCpusValue: function (test) {
        var localCpus = os.cpus();
        for (var i = 0; i < this.apiSystem.apiResponse['cpus'].length; i++) {
            test.strictEqual(typeof this.apiSystem.apiResponse['cpus'][i]['model'], 'string',
                            'cpus.model proerty is not string!');
            test.strictEqual(typeof this.apiSystem.apiResponse['cpus'][i]['speed'], 'number',
                            'cpus.speed proerty is not number!');
            test.strictEqual(this.apiSystem.apiResponse['cpus'][i]['model'], localCpus[i]['model'],
                            'local cpus.model value differs from the one from /api/system!');
            test.strictEqual(this.apiSystem.apiResponse['cpus'][i]['speed'], localCpus[i]['speed'],
                            'local cpus.speed value differs from the one from /api/system!');
        }
        test.done();
    },

    // network interfaces
    testApiSystemNetworkInterfacesValue: function(test) {
        var localNetworkInterfaces = os.networkInterfaces();
        test.deepEqual(this.apiSystem.apiResponse['networkinterfaces'], localNetworkInterfaces,
                                'local network interfaces differs from the one from /api/system!');
        test.done();
    }
};
<commit_msg>[RestAPI] Update judgement standard for cpus test<commit_after>var http = require('http');
var fs = require('fs');
var os = require('os');

var options = {
    host: '127.0.0.1',
    port: 8000,
    path: '/api/system',
    method: 'GET',
    headers: {
        'Accept': 'text/json'
    }
};

var apiSystem = {};
var responseJson = 'api_system.json';

function sendHttpRequest(opts) {
    var req = http.request(opts, function(res) {
        apiSystem.statusCode = res.statusCode;
        res.setEncoding('utf8');

        res.on('data', function(data) {
            apiSystem.apiResponse = JSON.parse(data);
               fs.writeFileSync(responseJson, JSON.stringify(apiSystem));
        });
    });
    req.end();
}

// First generate HTTP response file. Only node script will generate the
// json format response.
if (process.argv[1] == __filename) {
    sendHttpRequest(options);
}

module.exports = {
    setUp: function(callback) {
        var content = fs.readFileSync(responseJson);
        this.apiSystem = JSON.parse(content.toString());

        callback();
    },
    tearDown: function(callback) {
        callback();
    },

    // statue code
    testApiSystemStatusCode: function(test) {
        test.strictEqual(this.apiSystem.statusCode, 200,
                        'Response is not OK!');
        test.done();
    },

    // hostname
    testApiSystemHostnameNotNull: function(test) {
        test.ok('hostname' in this.apiSystem.apiResponse,
                    'hostname is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemHostnameType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['hostname'], 'string',
                        'hostname property is not string!');
        test.done();
    },
    testApiSystemHostnameValue: function(test) {
        test.strictEqual(this.apiSystem.apiResponse['hostname'], os.hostname(),
                        'local hostname value differs from the one from api response!');
        test.done();
    },

    // type
    testApiSystemTypeNotNull: function(test) {
        test.ok('type' in this.apiSystem.apiResponse,
                    'type is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemTypeType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['type'], 'string',
                        'type property is not string!');
        test.done();
    },
    testApiSystemTypeValue: function(test) {
        test.strictEqual(this.apiSystem.apiResponse['type'], os.type(),
                        'local type value differs from the one from api response!');
        test.done();
    },

    // arch
    testApiSystemArchNotNull: function(test) {
        test.ok('arch' in this.apiSystem.apiResponse,
                    'arch is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemArchType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['arch'], 'string',
                    'arch property is not string!');
        test.done();
    },
    testApiSystemArchValue: function (test) {
        test.strictEqual(this.apiSystem.apiResponse['arch'], os.arch(),
                        'local arch value differs from the one from /api/system!');
        test.done();
    },

    // release
    testApiSystemReleaseNotNull: function(test) {
        test.ok('release' in this.apiSystem.apiResponse,
                    'release is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemReleaseType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['release'], 'string',
                    'release property is not a string!');
        test.done();
    },
    testApiSystemReleaseValue: function (test) {
        test.strictEqual(this.apiSystem.apiResponse['release'], os.release(),
                        'local release value differs from the one from /api/system!');
        test.done();
    },

    // uptime
    testApiSystemUptimeNotNull: function(test) {
        test.ok('uptime' in this.apiSystem.apiResponse,
                    'uptime is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemUptimeType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['uptime'], 'number',
                    'uptime property is not a number!');
        test.done();
    },

    // loadavg
    testApiSystemLoadavgNotNull: function(test) {
        test.ok('loadavg' in this.apiSystem.apiResponse,
                    'loadavg is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemLoadavgType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['loadavg'], 'object',
                    'loadavg property is not an array!');

        for (var i = 0; i < this.apiSystem.apiResponse['loadavg'].length; i++) {
            test.strictEqual(typeof this.apiSystem.apiResponse['loadavg'][i], 'number',
                            'some item in loadavg property is not a number!');
        }
        test.done();
    },

    // totalmem
    testApiSystemTotalmemNotNull: function(test) {
        test.ok('totalmem' in this.apiSystem.apiResponse,
                    'totalmem is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemTotalmemType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['totalmem'], 'number',
                    'totalmem property is not a string!');
        test.done();
    },
    testApiSystemTotalmemValue: function (test) {
        test.strictEqual(this.apiSystem.apiResponse['totalmem'], os.totalmem(),
                        'local totalmem value differs from the one from /api/system!');
        test.done();
    },

    // freemem
    testApiSystemFreememNotNull: function(test) {
        test.ok('freemem' in this.apiSystem.apiResponse,
                    'freemem is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemFreememType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['freemem'], 'number',
                    'freemem property is not a string!');
        test.done();
    },

    // cpus
    testApiSystemCpusNotNull: function(test) {
        test.ok('cpus' in this.apiSystem.apiResponse,
                    'cpus is not a property in the response of /api/system!');
        test.done();
    },
    testApiSystemCpusType: function(test) {
        test.strictEqual(typeof this.apiSystem.apiResponse['cpus'], 'object',
                    'cpus property is not an array!');
        test.done();
    },
    testApiSystemCpusValue: function (test) {
        var localCpus = os.cpus();
        for (var i = 0; i < this.apiSystem.apiResponse['cpus'].length; i++) {
            test.strictEqual(typeof this.apiSystem.apiResponse['cpus'][i]['model'], 'string',
                            'cpus.model proerty is not string!');
            test.strictEqual(typeof this.apiSystem.apiResponse['cpus'][i]['speed'], 'number',
                            'cpus.speed proerty is not number!');
            test.strictEqual(this.apiSystem.apiResponse['cpus'][i]['model'], localCpus[i]['model'],
                            'local cpus.model value differs from the one from /api/system!');
        }
        test.done();
    },

    // network interfaces
    testApiSystemNetworkInterfacesValue: function(test) {
        var localNetworkInterfaces = os.networkInterfaces();
        test.deepEqual(this.apiSystem.apiResponse['networkinterfaces'], localNetworkInterfaces,
                                'local network interfaces differs from the one from /api/system!');
        test.done();
    }
};
<|endoftext|>


<commit_before>/** The systray icon.
 *
 * @module gui/js/tray
 */

const { Tray, Menu, MenuItem } = require('electron')
const { translate } = require('./i18n')
const path = require('path')

let tray = null

const imgs = path.resolve(__dirname, '..', 'images')
const isMac = process.platform === 'darwin'
const isWindows = process.platform === 'win32'
const isKde =
  process.env.XDG_CURRENT_DESKTOP &&
  process.env.XDG_CURRENT_DESKTOP.match(/KDE/)

module.exports.init = (app, listener) => {
  let icon = isMac
    ? `${imgs}/tray-icon-osx/idleTemplate.png`
    : isWindows
    ? `${imgs}/tray-icon-win/idle.png`
    : isKde
    ? `${imgs}/tray-icon-linux-kde/idle.png`
    : `${imgs}/tray-icon-linux/idle.png`
  tray = new Tray(icon)
  app.on('before-quit', () => tray.destroy())

  let cachedBounds = null
  const clicked = (e, bounds) => {
    cachedBounds = bounds && bounds.y !== 0 ? bounds : cachedBounds
    listener(tray.getBounds ? tray.getBounds() : cachedBounds)
  }

  // On Linux systems without libappindicator-gtk3 or other systems, clicks on
  // the systray icon trigger events that can be caught to display the app
  // window for example.
  tray.on('click', clicked)
  tray.on('right-click', clicked)
  tray.on('double-click', clicked)
  tray.setToolTip('loading')

  if (!isMac && !isWindows) {
    // When click events are not triggered, we need to display a context menu so
    // users can open the app's window.
    const cm = Menu.buildFromTemplate([
      { label: translate('Tray Quit application'), click: app.quit }
    ])
    cm.insert(
      0,
      new MenuItem({
        label: translate('Tray Show application'),
        click: clicked
      })
    )
    cm.insert(1, new MenuItem({ type: 'separator' }))
    tray.setContextMenu(cm)
  }
  setState('idle')
}

// old tray menu
/*
const goToTab = (tab) => {
  const alreadyShown = !!mainWindow
  showWindow()
  if (alreadyShown) {
    trayWindow.send('go-to-tab', tab)
  } else {
    mainWindow.webContents.once('dom-ready', () => {
      trayWindow.send('go-to-tab', tab)
    })
  }
}

const menu = Menu.buildFromTemplate([
  { label: statusLabel, enabled: false },
  { type: 'separator' },
  { label: translate('Tray Open Cozy folder'), click: openCozyFolder },
  { label: translate('Tray Go to my Cozy'), click: goToMyCozy },
  { type: 'separator' },
  { label: translate('Tray Help'), click: goToTab.bind(null, 'help') },
  { label: translate('Tray Settings'), click: goToTab.bind(null, 'settings') },
  { type: 'separator' },
  { label: translate('Tray Quit application'), click: app.quit }
])
if (!mainWindow) {
  menu.insert(2, new electron.MenuItem({
    label: translate('Tray Show application'), click: showWindow
  }))
}
if (state === 'error') {
  menu.insert(2, new electron.MenuItem({
    label: translate('Tray Relaunch synchronization'), click: () => { startSync(true) }
  }))
}
if (newReleaseAvailable) {
  menu.insert(2, new electron.MenuItem({
    label: translate('Tray A new release is available'), click: goToTab.bind(null, 'settings')
  }))
}
tray.setContextMenu(menu)
*/

var setState = (module.exports.setState = (state, filename) => {
  let statusLabel = ''
  let icon = 'idle'
  if (state === 'error') {
    icon = 'error'
    statusLabel = filename
  } else if (filename) {
    icon = 'sync'
    statusLabel = `${translate('Tray Syncing')} ‟${filename}“`
  } else if (state === 'up-to-date' || state === 'online') {
    icon = 'idle'
    statusLabel = translate('Tray Your cozy is up to date')
  } else if (state === 'syncing') {
    icon = 'sync'
    statusLabel = translate('Tray Syncing') + '…'
  } else if (state === 'offline') {
    icon = 'offline'
    statusLabel = translate('Tray Offline')
  }

  tray.setToolTip(statusLabel)
  if (process.platform === 'darwin') {
    tray.setImage(`${imgs}/tray-icon-osx/${icon}Template.png`)
    tray.setPressedImage(`${imgs}/tray-icon-osx/${icon}Highlight.png`)
  } else if (process.platform === 'win32') {
    tray.setImage(`${imgs}/tray-icon-win/${icon}.png`)
  } else if (
    process.env.XDG_CURRENT_DESKTOP &&
    process.env.XDG_CURRENT_DESKTOP.match(/KDE/)
  ) {
    tray.setImage(`${imgs}/tray-icon-linux-kde/${icon}.png`)
  } else {
    tray.setImage(`${imgs}/tray-icon-linux/${icon}.png`)
  }
})
<commit_msg>gui/tray: Add context menu on Windows (#1747)<commit_after>/** The systray icon.
 *
 * @module gui/js/tray
 */

const { Tray, Menu, MenuItem } = require('electron')
const { translate } = require('./i18n')
const path = require('path')

let tray = null

const imgs = path.resolve(__dirname, '..', 'images')
const isMac = process.platform === 'darwin'
const isWindows = process.platform === 'win32'
const isKde =
  process.env.XDG_CURRENT_DESKTOP &&
  process.env.XDG_CURRENT_DESKTOP.match(/KDE/)

module.exports.init = (app, listener) => {
  let icon = isMac
    ? `${imgs}/tray-icon-osx/idleTemplate.png`
    : isWindows
    ? `${imgs}/tray-icon-win/idle.png`
    : isKde
    ? `${imgs}/tray-icon-linux-kde/idle.png`
    : `${imgs}/tray-icon-linux/idle.png`
  tray = new Tray(icon)
  app.on('before-quit', () => tray.destroy())

  let cachedBounds = null
  const clicked = (e, bounds) => {
    cachedBounds = bounds && bounds.y !== 0 ? bounds : cachedBounds
    listener(tray.getBounds ? tray.getBounds() : cachedBounds)
  }

  // On Linux systems without libappindicator-gtk3 or other systems, clicks on
  // the systray icon trigger events that can be caught to display the app
  // window for example.
  tray.on('click', clicked)
  tray.on('right-click', clicked)
  tray.on('double-click', clicked)
  tray.setToolTip('loading')

  if (!isMac) {
    // When click events are not triggered, we need to display a context menu so
    // users can open the app's window.
    const cm = Menu.buildFromTemplate([
      { label: translate('Tray Quit application'), click: app.quit }
    ])
    cm.insert(
      0,
      new MenuItem({
        label: translate('Tray Show application'),
        click: clicked
      })
    )
    cm.insert(1, new MenuItem({ type: 'separator' }))
    tray.setContextMenu(cm)
  }
  setState('idle')
}

// old tray menu
/*
const goToTab = (tab) => {
  const alreadyShown = !!mainWindow
  showWindow()
  if (alreadyShown) {
    trayWindow.send('go-to-tab', tab)
  } else {
    mainWindow.webContents.once('dom-ready', () => {
      trayWindow.send('go-to-tab', tab)
    })
  }
}

const menu = Menu.buildFromTemplate([
  { label: statusLabel, enabled: false },
  { type: 'separator' },
  { label: translate('Tray Open Cozy folder'), click: openCozyFolder },
  { label: translate('Tray Go to my Cozy'), click: goToMyCozy },
  { type: 'separator' },
  { label: translate('Tray Help'), click: goToTab.bind(null, 'help') },
  { label: translate('Tray Settings'), click: goToTab.bind(null, 'settings') },
  { type: 'separator' },
  { label: translate('Tray Quit application'), click: app.quit }
])
if (!mainWindow) {
  menu.insert(2, new electron.MenuItem({
    label: translate('Tray Show application'), click: showWindow
  }))
}
if (state === 'error') {
  menu.insert(2, new electron.MenuItem({
    label: translate('Tray Relaunch synchronization'), click: () => { startSync(true) }
  }))
}
if (newReleaseAvailable) {
  menu.insert(2, new electron.MenuItem({
    label: translate('Tray A new release is available'), click: goToTab.bind(null, 'settings')
  }))
}
tray.setContextMenu(menu)
*/

var setState = (module.exports.setState = (state, filename) => {
  let statusLabel = ''
  let icon = 'idle'
  if (state === 'error') {
    icon = 'error'
    statusLabel = filename
  } else if (filename) {
    icon = 'sync'
    statusLabel = `${translate('Tray Syncing')} ‟${filename}“`
  } else if (state === 'up-to-date' || state === 'online') {
    icon = 'idle'
    statusLabel = translate('Tray Your cozy is up to date')
  } else if (state === 'syncing') {
    icon = 'sync'
    statusLabel = translate('Tray Syncing') + '…'
  } else if (state === 'offline') {
    icon = 'offline'
    statusLabel = translate('Tray Offline')
  }

  tray.setToolTip(statusLabel)
  if (process.platform === 'darwin') {
    tray.setImage(`${imgs}/tray-icon-osx/${icon}Template.png`)
    tray.setPressedImage(`${imgs}/tray-icon-osx/${icon}Highlight.png`)
  } else if (process.platform === 'win32') {
    tray.setImage(`${imgs}/tray-icon-win/${icon}.png`)
  } else if (
    process.env.XDG_CURRENT_DESKTOP &&
    process.env.XDG_CURRENT_DESKTOP.match(/KDE/)
  ) {
    tray.setImage(`${imgs}/tray-icon-linux-kde/${icon}.png`)
  } else {
    tray.setImage(`${imgs}/tray-icon-linux/${icon}.png`)
  }
})
<|endoftext|>


<commit_before>const seedData = [
  {
    "name": "Moved To San Francisco",
    "noteID": "1mv2",
    "type": "Life",
    "description": "Moved to SF from Raleigh, NC to begin the Hack Reactor software engineering immersive.",
    "location": "San Francisco, CA",
    "date": Date.now() - 500000
  }, {
    "name": "Began Work At Robert Half",
    "noteID": "2kk1",
    "type": "Professional",
    "description": "Accepted offer to work at Robert Half Technology, beginning January 2017.",
    "location": "San Ramon, CA",
    "date": Date.now() - 1000000
  }, {
    "name": "Date of Birth",
    "noteID": "3ihl",
    "type": "Life",
    "description": "The day I came into this world. Alas... to be alive!",
    "location": "Jonesboro, AK",
    "date": Date.now() - 2000000
  }, {
    "name": "Began School At The University of North Carolina at Chapel Hill",
    "noteID": "441k",
    "type": "Education",
    "description": "Started university majoring in polymer chemistry and with ambitions of becoming a research scientist.",
    "location": "Chapel Hill, NC",
    "date": Date.now() - 4000000
  }, {
    "name": "Graduated From Hack Reactor",
    "noteID": "5kso",
    "type": "Education",
    "description": "Date of matriculation from the world's 2nd best (after App Academy) software engineering immersive — Hack Reactor!",
    "location": "San Francisco, CA",
    "date": Date.now() - 8000000
  }
];

module.exports = seedData;
<commit_msg>Update seed_data.js<commit_after>const seedData = [
  {
    "name": "Moved To San Francisco",
    "noteID": "1mv2",
    "type": "Life",
    "description": "Moved to SF from Raleigh, NC to begin the Hack Reactor software engineering immersive.",
    "location": "San Francisco, CA",
    "date": Date.now() - 500000
  }, {
    "name": "Began Work At Robert Half",
    "noteID": "2kk1",
    "type": "Professional",
    "description": "Accepted offer to work at Robert Half Technology, beginning January 2017.",
    "location": "San Ramon, CA",
    "date": Date.now() - 1000000
  }, {
    "name": "Date of Birth",
    "noteID": "3ihl",
    "type": "Life",
    "description": "The day I came into this world. Alas... to be alive!",
    "location": "Jonesboro, AK",
    "date": Date.now() - 2000000
  }, {
    "name": "Began School At The University of North Carolina at Chapel Hill",
    "noteID": "441k",
    "type": "Education",
    "description": "Started university majoring in polymer chemistry and with ambitions of becoming a research scientist.",
    "location": "Chapel Hill, NC",
    "date": Date.now() - 4000000
  }, {
    "name": "Graduated From Hack Reactor",
    "noteID": "5kso",
    "type": "Education",
    "description": "Date of matriculation from the world's best software engineering immersive — Hack Reactor!",
    "location": "San Francisco, CA",
    "date": Date.now() - 8000000
  }
];

module.exports = seedData;
<|endoftext|>


<commit_before>import { LightningElement, track, wire, api } from "lwc";
import { refreshApex } from "@salesforce/apex";
import { ShowToastEvent } from "lightning/platformShowToastEvent";
import getAutoEnrollmentMappingsVModel from "@salesforce/apex/ProgramSettingsController.getAutoEnrollmentMappingsVModel";
import updateAutoEnrollmentMappings from "@salesforce/apex/ProgramSettingsController.updateAutoEnrollmentMappings";

// Controller for Affiliations created with Program Enrollment
import getAffiliationsWithProgramEnrollmentVModel from "@salesforce/apex/AffiliationsWithProgramEnrollController.getAffiliationsWithProgramEnrollmentVModel";

//Custom labels for Affiliations created with Program Enrollment
import stgHelpAfflCreateFromProgramEnrollmentHeader from "@salesforce/label/c.stgHelpAfflCreateFromProgramEnrollmentHeader";
import stgHelpAfflCreateFromProgramEnrollmentInfo from "@salesforce/label/c.stgHelpAfflCreateFromProgramEnrollmentInfo";
import stgAfflProgramEnrollmentSettingsTitle from "@salesforce/label/c.stgAfflProgramEnrollmentSettingsTitle";
import stgAfflProgEnrollSetRoleValue from "@salesforce/label/c.stgAfflProgEnrollSetRoleValue";
import stgHelpAfflProgEnrollSetRoleValue from "@salesforce/label/c.stgHelpAfflProgEnrollSetRoleValue";
import stgAfflProgEnrollSetStatusValue from "@salesforce/label/c.stgAfflProgEnrollSetStatusValue";
import stgHelpAfflProgEnrollSetStatusValue from "@salesforce/label/c.stgHelpAfflProgEnrollSetStatusValue";
import stgAfflCopyProgramEnrollmentEndDate from "@salesforce/label/c.stgAfflCopyProgramEnrollmentEndDate";
import stgHelpAfflCopyProgramEnrollmentEndDate from "@salesforce/label/c.stgHelpAfflCopyProgramEnrollmentEndDate";
import stgAfflCopyProgramEnrollmentStartDate from "@salesforce/label/c.stgAfflCopyProgramEnrollmentStartDate";
import stgHelpAfflCopyProgramEnrollmentStartDate from "@salesforce/label/c.stgHelpAfflCopyProgramEnrollmentStartDate";
import stgOptSelect from "@salesforce/label/c.stgOptSelect";

//custom labels for Auto Enrollment Mappings
import getProgramEnrollmentDeletionSettingsVModel from "@salesforce/apex/ProgramSettingsController.getProgramEnrollmentDeletionSettingsVModel";

//custom labels
import stgProgramsSettingsTitle from "@salesforce/label/c.stgProgramsSettingsTitle";
import stgBtnEdit from "@salesforce/label/c.stgBtnEdit";
import stgBtnDelete from "@salesforce/label/c.stgBtnDelete";
import autoEnrollmentMappingsTitle from "@salesforce/label/c.stgAutoEnrollmentProgramTitle";
import autoEnrollmentMappingsDescription from "@salesforce/label/c.stgAutoEnrollmentProgramDesc";
import stgColAccountRecordType from "@salesforce/label/c.stgColAccountRecordType";
import stgColAutoEnrollmentStatus from "@salesforce/label/c.stgColAutoEnrollmentStatus";
import stgColAutoEnrollmentRole from "@salesforce/label/c.stgColAutoEnrollmentRole";
import stgBtnAddMapping from "@salesforce/label/c.stgBtnAddMapping";
import stgAutoEnrollmentEditSuccess from "@salesforce/label/c.stgAutoEnrollmentEditSuccess";
import stgAfflProgEnrollDeleteTitle from "@salesforce/label/c.stgAfflProgEnrollDeleteTitle";
import stgAfflProgEnrollDeleteRelated from "@salesforce/label/c.stgAfflProgEnrollDeleteRelated";
import AfflProgEnrollDeleted from "@salesforce/label/c.AfflProgEnrollDeleted";
import stgAfflDeleteProgramEnrollment from "@salesforce/label/c.stgAfflDeleteProgramEnrollment";
import stgHelpAfflDeleteProgramEnrollment from "@salesforce/label/c.stgHelpAfflDeleteProgramEnrollment";
import stgOptSelect from "@salesforce/label/c.stgOptSelect";
export default class programSettings extends LightningElement {
    isEditMode = false;
    affordancesDisabledToggle = false;

    @track autoEnrollmentMappingsVModel;
    @track autoEnrollmentMappingsVModelWireResult;
    @track affiliationsWithProgramEnrollmentVModel;
    @track affiliationsWithProgramEnrollVModelWireResult;
    @track programSettingsVModel;
    @track programSettingsVModelWireResult;

    @track programEnrollmentDeletionSettingsVModel;
    @track programEnrollmentDeletionSettingsVModelWireResult;
    @track showProgramEnrollmentDeletionStatus;

    labelReference = {
        programsSettingsTitle: stgProgramsSettingsTitle,
        newButton: stgBtnAddMapping,
        afflCreateFromPrgrmHeading: stgHelpAfflCreateFromProgramEnrollmentHeader,
        afflCreateFromPrgrmInfo: stgHelpAfflCreateFromProgramEnrollmentInfo,
        afflProgramEnrollmentSettingsTitle: stgAfflProgramEnrollmentSettingsTitle,
        afflProgEnrollSetRoleValue: stgAfflProgEnrollSetRoleValue,
        helpAfflProgEnrollSetRoleValue: stgHelpAfflProgEnrollSetRoleValue,
        afflProgEnrollSetStatusValue: stgAfflProgEnrollSetStatusValue,
        helpAfflProgEnrollSetStatusValue: stgHelpAfflProgEnrollSetStatusValue,
        afflCopyProgramEnrollmentEndDate: stgAfflCopyProgramEnrollmentEndDate,
        helpAfflCopyProgramEnrollmentEndDate: stgHelpAfflCopyProgramEnrollmentEndDate,
        afflCopyProgramEnrollmentStartDate: stgAfflCopyProgramEnrollmentStartDate,
        helpAfflCopyProgramEnrollmentStartDate: stgHelpAfflCopyProgramEnrollmentStartDate,
        placeHolderText: stgOptSelect,
        programEnrollmentDeletionHeading: stgAfflProgEnrollDeleteTitle,
        programEnrollmentDeletionSettingTitle: stgAfflProgEnrollDeleteRelated,
        programEnrollmentDeletionSettingDescription: AfflProgEnrollDeleted,
        programEnrollmentDeletionStatusSettingTitle: stgAfflDeleteProgramEnrollment,
        programEnrollmentDeletionStatusSettingDescription: stgHelpAfflDeleteProgramEnrollment,

        autoEnrollmentMappingsTable: {
            autoEnrollmentMappingsTitle: autoEnrollmentMappingsTitle,
            autoEnrollmentMappingsDescription: autoEnrollmentMappingsDescription,
            accountRecordTypeColumn: stgColAccountRecordType,
            autoEnrollmentStatusColumn: stgColAutoEnrollmentStatus,
            autoEnrollmentRoleColumn: stgColAutoEnrollmentRole,
            editAction: stgBtnEdit,
            deleteAction: stgBtnDelete,
        },
        editSuccessMessage: stgAutoEnrollmentEditSuccess,
    };

    inputAttributeReference = {
        createdAfflRoleComboboxId: "createdAfflRole",
        createdAfflStatusComboboxId: "createdAfflStatus",
        copyEndDateComboboxId: "copyEndDate",
        copyStartDateComboboxId: "copyStartDate",
        programEnrollmentDeletionToggleId: "programEnrollmentDeletions",
        programEnrollmentDeletionStatusComboboxId: "programEnrollmentDeletionStatus",
    };

    get affordancesDisabled() {
        if (!this.isEditMode || this.affordancesDisabledToggle === true) {
            return true;
        }
        return undefined;
    }

    @wire(getAutoEnrollmentMappingsVModel)
    autoEnrollmentMappingsVModelWire(result) {
        this.autoEnrollmentMappingsVModelWireResult = result;

        if (result.data) {
            this.autoEnrollmentMappingsVModel = result.data;
        } else if (result.error) {
            //console.log("error retrieving preferredContactInfoSettingsVModel");
        }
    }

    @api
    handleSaveCanvasRender() {
        this.template.querySelector("c-settings-save-canvas").focusOnTitle();
    }

    @wire(getAffiliationsWithProgramEnrollmentVModel)
    affiliationsWithProgramEnrollmentVModelWire(result) {
        this.affiliationsWithProgramEnrollVModelWireResult = result;

        if (result.data) {
            this.affiliationsWithProgramEnrollmentVModel = result.data;
        } else if (result.error) {
            //console.log("error retrieving preferredContactInfoSettingsVModel");
        }
    }

    handleRoleForCreatedAfflChange(event) {
        this.handleSpecifyRoleForCreatedAffiliaitons(event);
        var affiliationRole = event.detail.value;
        if (event.detail.value === '""') {
            // set Hierarchy Settings field to a blank value (not "")
            affiliationRole = "";
        }
        // add updated setting to hierarchySettingsChanges object
        let hierarchySettingsChange = {
            settingsType: "string",
            settingsName: "Affl_ProgEnroll_Role_Map__c",
            settingsValue: affiliationRole,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    handleSpecifyRoleForCreatedAffiliaitons(event) {
        var specifyRoleForCreatedAffl = event.detail.value;
        if (event.detail.value === '""') {
            // set Hierarchy Settings field to a blank value (not "")
            specifyRoleForCreatedAffl = false;
        } else {
            specifyRoleForCreatedAffl = true;
        }
        // add updated setting to hierarchySettingsChanges object
        let hierarchySettingsChange = {
            settingsType: "boolean",
            settingsName: "Affl_ProgEnroll_Set_Role__c",
            settingsValue: specifyRoleForCreatedAffl,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    handleStatusForCreatedAfflChange(event) {
        var affiliationStatus = event.detail.value;
        if (event.detail.value === '""') {
            // set Hierarchy Settings field to a blank value (not "")
            affiliationStatus = "";
        }
        // add updated setting to hierarchySettingsChanges object
        let hierarchySettingsChange = {
            settingsType: "string",
            settingsName: "Affl_ProgEnroll_Status_Map__c",
            settingsValue: affiliationStatus,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    handleCopyEndDateChange(event) {
        // add updated setting to hierarchySettingsChanges object
        let hierarchySettingsChange = {
            settingsType: "boolean",
            settingsName: "Affl_ProgEnroll_Copy_End_Date__c",
            settingsValue: event.detail.value,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    handleCopyStartDateChange(event) {
        // add updated setting to hierarchySettingsChanges object
        let hierarchySettingsChange = {
            settingsType: "boolean",
            settingsName: "Affl_ProgEnroll_Copy_Start_Date__c",
            settingsValue: event.detail.value,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    @wire(getProgramEnrollmentDeletionSettingsVModel)
    programEnrollmentDeletionSettingsVModelWire(result) {
        this.programEnrollmentDeletionSettingsVModelWireResult = result;

        if (result.data) {
            this.programEnrollmentDeletionSettingsVModel = result.data;

            // program enrollment deletion status visibility dependent on program enrollment deletion setting
            this.showProgramEnrollmentDeletionStatus = !this.programEnrollmentDeletionSettingsVModel
                .programEnrollmentDeletion;
        } else if (result.error) {
            console.log("error retrieving ProgramEnrollmentDeletionSettingsVModel");
        }
    }

    get autoEnrollmentMappingsTableColumns() {
        return [
            {
                label: this.labelReference.autoEnrollmentMappingsTable.accountRecordTypeColumn,
                fieldName: "accountRecordTypeLabel",
            },
            {
                label: this.labelReference.autoEnrollmentMappingsTable.autoEnrollmentStatusColumn,
                fieldName: "autoProgramEnrollmentStatus",
            },
            {
                label: this.labelReference.autoEnrollmentMappingsTable.autoEnrollmentRoleColumn,
                fieldName: "autoProgramEnrollmentRole",
            },
            {
                type: "action",
                typeAttributes: {
                    rowActions: [
                        { label: this.labelReference.autoEnrollmentMappingsTable.editAction, name: "edit" },
                        { label: this.labelReference.autoEnrollmentMappingsTable.deleteAction, name: "delete" },
                    ],
                },
            },
        ];
    }

    handleSettingsEditModeChange(event) {
        this.isEditMode = !event.detail;
        this.affordancesDisabledToggle = event.detail;
    }

    handleSettingsSaving(event) {
        this.affordancesDisabledToggle = true;
        // TODO: perform client side validation

        // if validation fails, call this.handleValidationFailure()
        //this.template.querySelector("c-settings-save-canvas").handleValidationFailure();

        // else, update hierarchy settings
        this.template.querySelector("c-settings-save-canvas").updateHierarchySettings();
    }

    handleSettingsSaveCompleted(event) {
        this.affordancesDisabledToggle = false;
        this.refreshAllApex();
    }

    handleSettingsSaveCancel(event) {
        this.refreshAllApex();
    }

    handleProgramEnrollmentDeletionChange(event) {
        const eventDetail = event.detail;

        // display program enrollment deletion status setting if program enrollment deletion disabled
        this.showProgramEnrollmentDeletionStatus = !eventDetail.value;

        let hierarchySettingsChange = {
            settingsType: "boolean",
            settingsName: "Affl_ProgEnroll_Del__c",
            settingsValue: eventDetail.value,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    handleProgramEnrollmentDeletionStatusChange(event) {
        let hierarchySettingsChange = {
            settingsType: "string",
            settingsName: "Affl_ProgEnroll_Del_Status__c",
            settingsValue: event.detail.value,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    refreshAllApex() {
        Promise.all([
            refreshApex(this.autoEnrollmentMappingsVModelWireResult),
            refreshApex(this.programSettingsVModelWireResult),
            refreshApex(this.affiliationsWithProgramEnrollVModelWireResult),
            refreshApex(this.programEnrollmentDeletionSettingsVModelWireResult),
        ]).then(() => {
            this.showProgramEnrollmentDeletionStatus = !this.programEnrollmentDeletionSettingsVModel
                .programEnrollmentDeletion;

            this.template.querySelectorAll("c-settings-row-input").forEach((input) => {
                input.resetValue();
            });
        });
    }

    get autoEnrollmentMappingsDescriptionRichText() {
        return (
            this.labelReference.autoEnrollmentMappingsTable.autoEnrollmentMappingsDescription +
            " " +
            this.autoEnrollmentHyperLink
        );
    }

    handleNewAutoEnrollmentMappingClick(event) {}

    handleAutoEnrollmentMappingRowAction(event) {
        const actionName = event.detail.action.name;
        const actionRow = event.detail.row;
        this.dispatchAutoEnrollmentEditModalRequestEvent(actionName, actionRow);
    }

    dispatchAutoEnrollmentEditModalRequestEvent(actionName, actionRow) {
        const autoEnrollmentEditDetail = {
            actionName: actionName,
            mappingName: actionRow.mappingName,
            accountRecordType: actionRow.accountRecordTypeName,
            autoProgramEnrollmentStatus: actionRow.autoProgramEnrollmentStatus,
            autoProgramEnrollmentRole: actionRow.autoProgramEnrollmentRole,
        };

        const autoEnrollmentEditModalRequestEvent = new CustomEvent("autoenrollmenteditmodalrequest", {
            detail: autoEnrollmentEditDetail,
            bubbles: true,
            composed: true,
        });

        this.dispatchEvent(autoEnrollmentEditModalRequestEvent);
    }

    @api modalSave(saveModel) {
        switch (saveModel.action) {
            /*case "create":
                this.insertAffiliations(saveModel.mappingName, saveModel.accountRecordType, saveModel.contactField);
                break;*/
            case "edit":
                this.updateAutoEnrollmentMappings(
                    saveModel.mappingName,
                    saveModel.oldAccountRecordType,
                    saveModel.newAccountRecordType,
                    saveModel.autoProgramEnrollmentStatus,
                    saveModel.autoProgramEnrollmentRole
                );
                break;
            /*case "delete":
                this.deleteAffiliation(saveModel.mappingName);
                break;*/
        }
    }

    updateAutoEnrollmentMappings(
        mappingName,
        oldAccountRecordType,
        newAccountRecordType,
        autoProgramEnrollmentStatus,
        autoProgramEnrollmentRole
    ) {
        updateAutoEnrollmentMappings({
            mappingName: mappingName,
            oldAccountRecordType: oldAccountRecordType,
            newAccountRecordType: newAccountRecordType,
            autoProgramEnrollmentStatus: autoProgramEnrollmentStatus,
            autoProgramEnrollmentRole: autoProgramEnrollmentRole,
        })
            .then((result) => {
                this.showToast(
                    "success",
                    "Update Complete",
                    this.labelReference.editSuccessMessage.replace("{0}", result)
                );
            })

            .catch((error) => {
                // console.log('Inside error');
            });
        this.refreshAllApex();
    }

    showToast(toastType, toastTitle, toastMessage) {
        const showToastEvent = new ShowToastEvent({
            title: toastTitle,
            message: toastMessage,
            variant: toastType,
            mode: "dismissable",
        });
        this.dispatchEvent(showToastEvent);
    }
}
<commit_msg>fixing wrong merge conflicts<commit_after>import { LightningElement, track, wire, api } from "lwc";
import { refreshApex } from "@salesforce/apex";
import { ShowToastEvent } from "lightning/platformShowToastEvent";
import getAutoEnrollmentMappingsVModel from "@salesforce/apex/ProgramSettingsController.getAutoEnrollmentMappingsVModel";
import updateAutoEnrollmentMappings from "@salesforce/apex/ProgramSettingsController.updateAutoEnrollmentMappings";

// Controller for Affiliations created with Program Enrollment
import getAffiliationsWithProgramEnrollmentVModel from "@salesforce/apex/AffiliationsWithProgramEnrollController.getAffiliationsWithProgramEnrollmentVModel";

//Custom labels for Affiliations created with Program Enrollment
import stgHelpAfflCreateFromProgramEnrollmentHeader from "@salesforce/label/c.stgHelpAfflCreateFromProgramEnrollmentHeader";
import stgHelpAfflCreateFromProgramEnrollmentInfo from "@salesforce/label/c.stgHelpAfflCreateFromProgramEnrollmentInfo";
import stgAfflProgramEnrollmentSettingsTitle from "@salesforce/label/c.stgAfflProgramEnrollmentSettingsTitle";
import stgAfflProgEnrollSetRoleValue from "@salesforce/label/c.stgAfflProgEnrollSetRoleValue";
import stgHelpAfflProgEnrollSetRoleValue from "@salesforce/label/c.stgHelpAfflProgEnrollSetRoleValue";
import stgAfflProgEnrollSetStatusValue from "@salesforce/label/c.stgAfflProgEnrollSetStatusValue";
import stgHelpAfflProgEnrollSetStatusValue from "@salesforce/label/c.stgHelpAfflProgEnrollSetStatusValue";
import stgAfflCopyProgramEnrollmentEndDate from "@salesforce/label/c.stgAfflCopyProgramEnrollmentEndDate";
import stgHelpAfflCopyProgramEnrollmentEndDate from "@salesforce/label/c.stgHelpAfflCopyProgramEnrollmentEndDate";
import stgAfflCopyProgramEnrollmentStartDate from "@salesforce/label/c.stgAfflCopyProgramEnrollmentStartDate";
import stgHelpAfflCopyProgramEnrollmentStartDate from "@salesforce/label/c.stgHelpAfflCopyProgramEnrollmentStartDate";
import stgOptSelect from "@salesforce/label/c.stgOptSelect";

//custom labels for Auto Enrollment Mappings
import getProgramEnrollmentDeletionSettingsVModel from "@salesforce/apex/ProgramSettingsController.getProgramEnrollmentDeletionSettingsVModel";

//custom labels
import stgProgramsSettingsTitle from "@salesforce/label/c.stgProgramsSettingsTitle";
import stgBtnEdit from "@salesforce/label/c.stgBtnEdit";
import stgBtnDelete from "@salesforce/label/c.stgBtnDelete";
import autoEnrollmentMappingsTitle from "@salesforce/label/c.stgAutoEnrollmentProgramTitle";
import autoEnrollmentMappingsDescription from "@salesforce/label/c.stgAutoEnrollmentProgramDesc";
import stgColAccountRecordType from "@salesforce/label/c.stgColAccountRecordType";
import stgColAutoEnrollmentStatus from "@salesforce/label/c.stgColAutoEnrollmentStatus";
import stgColAutoEnrollmentRole from "@salesforce/label/c.stgColAutoEnrollmentRole";
import stgBtnAddMapping from "@salesforce/label/c.stgBtnAddMapping";
import stgAutoEnrollmentEditSuccess from "@salesforce/label/c.stgAutoEnrollmentEditSuccess";
import stgAfflProgEnrollDeleteTitle from "@salesforce/label/c.stgAfflProgEnrollDeleteTitle";
import stgAfflProgEnrollDeleteRelated from "@salesforce/label/c.stgAfflProgEnrollDeleteRelated";
import AfflProgEnrollDeleted from "@salesforce/label/c.AfflProgEnrollDeleted";
import stgAfflDeleteProgramEnrollment from "@salesforce/label/c.stgAfflDeleteProgramEnrollment";
import stgHelpAfflDeleteProgramEnrollment from "@salesforce/label/c.stgHelpAfflDeleteProgramEnrollment";
export default class programSettings extends LightningElement {
    isEditMode = false;
    affordancesDisabledToggle = false;

    @track autoEnrollmentMappingsVModel;
    @track autoEnrollmentMappingsVModelWireResult;
    @track affiliationsWithProgramEnrollmentVModel;
    @track affiliationsWithProgramEnrollVModelWireResult;
    @track programSettingsVModel;
    @track programSettingsVModelWireResult;

    @track programEnrollmentDeletionSettingsVModel;
    @track programEnrollmentDeletionSettingsVModelWireResult;
    @track showProgramEnrollmentDeletionStatus;

    labelReference = {
        programsSettingsTitle: stgProgramsSettingsTitle,
        newButton: stgBtnAddMapping,
        afflCreateFromPrgrmHeading: stgHelpAfflCreateFromProgramEnrollmentHeader,
        afflCreateFromPrgrmInfo: stgHelpAfflCreateFromProgramEnrollmentInfo,
        afflProgramEnrollmentSettingsTitle: stgAfflProgramEnrollmentSettingsTitle,
        afflProgEnrollSetRoleValue: stgAfflProgEnrollSetRoleValue,
        helpAfflProgEnrollSetRoleValue: stgHelpAfflProgEnrollSetRoleValue,
        afflProgEnrollSetStatusValue: stgAfflProgEnrollSetStatusValue,
        helpAfflProgEnrollSetStatusValue: stgHelpAfflProgEnrollSetStatusValue,
        afflCopyProgramEnrollmentEndDate: stgAfflCopyProgramEnrollmentEndDate,
        helpAfflCopyProgramEnrollmentEndDate: stgHelpAfflCopyProgramEnrollmentEndDate,
        afflCopyProgramEnrollmentStartDate: stgAfflCopyProgramEnrollmentStartDate,
        helpAfflCopyProgramEnrollmentStartDate: stgHelpAfflCopyProgramEnrollmentStartDate,
        placeHolderText: stgOptSelect,
        programEnrollmentDeletionHeading: stgAfflProgEnrollDeleteTitle,
        programEnrollmentDeletionSettingTitle: stgAfflProgEnrollDeleteRelated,
        programEnrollmentDeletionSettingDescription: AfflProgEnrollDeleted,
        programEnrollmentDeletionStatusSettingTitle: stgAfflDeleteProgramEnrollment,
        programEnrollmentDeletionStatusSettingDescription: stgHelpAfflDeleteProgramEnrollment,

        autoEnrollmentMappingsTable: {
            autoEnrollmentMappingsTitle: autoEnrollmentMappingsTitle,
            autoEnrollmentMappingsDescription: autoEnrollmentMappingsDescription,
            accountRecordTypeColumn: stgColAccountRecordType,
            autoEnrollmentStatusColumn: stgColAutoEnrollmentStatus,
            autoEnrollmentRoleColumn: stgColAutoEnrollmentRole,
            editAction: stgBtnEdit,
            deleteAction: stgBtnDelete,
        },
        editSuccessMessage: stgAutoEnrollmentEditSuccess,
    };

    inputAttributeReference = {
        createdAfflRoleComboboxId: "createdAfflRole",
        createdAfflStatusComboboxId: "createdAfflStatus",
        copyEndDateComboboxId: "copyEndDate",
        copyStartDateComboboxId: "copyStartDate",
        programEnrollmentDeletionToggleId: "programEnrollmentDeletions",
        programEnrollmentDeletionStatusComboboxId: "programEnrollmentDeletionStatus",
    };

    get affordancesDisabled() {
        if (!this.isEditMode || this.affordancesDisabledToggle === true) {
            return true;
        }
        return undefined;
    }

    @wire(getAutoEnrollmentMappingsVModel)
    autoEnrollmentMappingsVModelWire(result) {
        this.autoEnrollmentMappingsVModelWireResult = result;

        if (result.data) {
            this.autoEnrollmentMappingsVModel = result.data;
        } else if (result.error) {
            //console.log("error retrieving preferredContactInfoSettingsVModel");
        }
    }

    @api
    handleSaveCanvasRender() {
        this.template.querySelector("c-settings-save-canvas").focusOnTitle();
    }

    @wire(getAffiliationsWithProgramEnrollmentVModel)
    affiliationsWithProgramEnrollmentVModelWire(result) {
        this.affiliationsWithProgramEnrollVModelWireResult = result;

        if (result.data) {
            this.affiliationsWithProgramEnrollmentVModel = result.data;
        } else if (result.error) {
            //console.log("error retrieving preferredContactInfoSettingsVModel");
        }
    }

    handleRoleForCreatedAfflChange(event) {
        this.handleSpecifyRoleForCreatedAffiliaitons(event);
        var affiliationRole = event.detail.value;
        if (event.detail.value === '""') {
            // set Hierarchy Settings field to a blank value (not "")
            affiliationRole = "";
        }
        // add updated setting to hierarchySettingsChanges object
        let hierarchySettingsChange = {
            settingsType: "string",
            settingsName: "Affl_ProgEnroll_Role_Map__c",
            settingsValue: affiliationRole,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    handleSpecifyRoleForCreatedAffiliaitons(event) {
        var specifyRoleForCreatedAffl = event.detail.value;
        if (event.detail.value === '""') {
            // set Hierarchy Settings field to a blank value (not "")
            specifyRoleForCreatedAffl = false;
        } else {
            specifyRoleForCreatedAffl = true;
        }
        // add updated setting to hierarchySettingsChanges object
        let hierarchySettingsChange = {
            settingsType: "boolean",
            settingsName: "Affl_ProgEnroll_Set_Role__c",
            settingsValue: specifyRoleForCreatedAffl,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    handleStatusForCreatedAfflChange(event) {
        var affiliationStatus = event.detail.value;
        if (event.detail.value === '""') {
            // set Hierarchy Settings field to a blank value (not "")
            affiliationStatus = "";
        }
        // add updated setting to hierarchySettingsChanges object
        let hierarchySettingsChange = {
            settingsType: "string",
            settingsName: "Affl_ProgEnroll_Status_Map__c",
            settingsValue: affiliationStatus,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    handleCopyEndDateChange(event) {
        // add updated setting to hierarchySettingsChanges object
        let hierarchySettingsChange = {
            settingsType: "boolean",
            settingsName: "Affl_ProgEnroll_Copy_End_Date__c",
            settingsValue: event.detail.value,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    handleCopyStartDateChange(event) {
        // add updated setting to hierarchySettingsChanges object
        let hierarchySettingsChange = {
            settingsType: "boolean",
            settingsName: "Affl_ProgEnroll_Copy_Start_Date__c",
            settingsValue: event.detail.value,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    @wire(getProgramEnrollmentDeletionSettingsVModel)
    programEnrollmentDeletionSettingsVModelWire(result) {
        this.programEnrollmentDeletionSettingsVModelWireResult = result;

        if (result.data) {
            this.programEnrollmentDeletionSettingsVModel = result.data;

            // program enrollment deletion status visibility dependent on program enrollment deletion setting
            this.showProgramEnrollmentDeletionStatus = !this.programEnrollmentDeletionSettingsVModel
                .programEnrollmentDeletion;
        } else if (result.error) {
            console.log("error retrieving ProgramEnrollmentDeletionSettingsVModel");
        }
    }

    get autoEnrollmentMappingsTableColumns() {
        return [
            {
                label: this.labelReference.autoEnrollmentMappingsTable.accountRecordTypeColumn,
                fieldName: "accountRecordTypeLabel",
            },
            {
                label: this.labelReference.autoEnrollmentMappingsTable.autoEnrollmentStatusColumn,
                fieldName: "autoProgramEnrollmentStatus",
            },
            {
                label: this.labelReference.autoEnrollmentMappingsTable.autoEnrollmentRoleColumn,
                fieldName: "autoProgramEnrollmentRole",
            },
            {
                type: "action",
                typeAttributes: {
                    rowActions: [
                        { label: this.labelReference.autoEnrollmentMappingsTable.editAction, name: "edit" },
                        { label: this.labelReference.autoEnrollmentMappingsTable.deleteAction, name: "delete" },
                    ],
                },
            },
        ];
    }

    handleSettingsEditModeChange(event) {
        this.isEditMode = !event.detail;
        this.affordancesDisabledToggle = event.detail;
    }

    handleSettingsSaving(event) {
        this.affordancesDisabledToggle = true;
        // TODO: perform client side validation

        // if validation fails, call this.handleValidationFailure()
        //this.template.querySelector("c-settings-save-canvas").handleValidationFailure();

        // else, update hierarchy settings
        this.template.querySelector("c-settings-save-canvas").updateHierarchySettings();
    }

    handleSettingsSaveCompleted(event) {
        this.affordancesDisabledToggle = false;
        this.refreshAllApex();
    }

    handleSettingsSaveCancel(event) {
        this.refreshAllApex();
    }

    handleProgramEnrollmentDeletionChange(event) {
        const eventDetail = event.detail;

        // display program enrollment deletion status setting if program enrollment deletion disabled
        this.showProgramEnrollmentDeletionStatus = !eventDetail.value;

        let hierarchySettingsChange = {
            settingsType: "boolean",
            settingsName: "Affl_ProgEnroll_Del__c",
            settingsValue: eventDetail.value,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    handleProgramEnrollmentDeletionStatusChange(event) {
        let hierarchySettingsChange = {
            settingsType: "string",
            settingsName: "Affl_ProgEnroll_Del_Status__c",
            settingsValue: event.detail.value,
        };

        this.template.querySelector("c-settings-save-canvas").handleHierarchySettingsChange(hierarchySettingsChange);
    }

    refreshAllApex() {
        Promise.all([
            refreshApex(this.autoEnrollmentMappingsVModelWireResult),
            refreshApex(this.programSettingsVModelWireResult),
            refreshApex(this.affiliationsWithProgramEnrollVModelWireResult),
            refreshApex(this.programEnrollmentDeletionSettingsVModelWireResult),
        ]).then(() => {
            this.showProgramEnrollmentDeletionStatus = !this.programEnrollmentDeletionSettingsVModel
                .programEnrollmentDeletion;

            this.template.querySelectorAll("c-settings-row-input").forEach((input) => {
                input.resetValue();
            });
        });
    }

    get autoEnrollmentMappingsDescriptionRichText() {
        return (
            this.labelReference.autoEnrollmentMappingsTable.autoEnrollmentMappingsDescription +
            " " +
            this.autoEnrollmentHyperLink
        );
    }

    handleNewAutoEnrollmentMappingClick(event) {}

    handleAutoEnrollmentMappingRowAction(event) {
        const actionName = event.detail.action.name;
        const actionRow = event.detail.row;
        this.dispatchAutoEnrollmentEditModalRequestEvent(actionName, actionRow);
    }

    dispatchAutoEnrollmentEditModalRequestEvent(actionName, actionRow) {
        const autoEnrollmentEditDetail = {
            actionName: actionName,
            mappingName: actionRow.mappingName,
            accountRecordType: actionRow.accountRecordTypeName,
            autoProgramEnrollmentStatus: actionRow.autoProgramEnrollmentStatus,
            autoProgramEnrollmentRole: actionRow.autoProgramEnrollmentRole,
        };

        const autoEnrollmentEditModalRequestEvent = new CustomEvent("autoenrollmenteditmodalrequest", {
            detail: autoEnrollmentEditDetail,
            bubbles: true,
            composed: true,
        });

        this.dispatchEvent(autoEnrollmentEditModalRequestEvent);
    }

    @api modalSave(saveModel) {
        switch (saveModel.action) {
            /*case "create":
                this.insertAffiliations(saveModel.mappingName, saveModel.accountRecordType, saveModel.contactField);
                break;*/
            case "edit":
                this.updateAutoEnrollmentMappings(
                    saveModel.mappingName,
                    saveModel.oldAccountRecordType,
                    saveModel.newAccountRecordType,
                    saveModel.autoProgramEnrollmentStatus,
                    saveModel.autoProgramEnrollmentRole
                );
                break;
            /*case "delete":
                this.deleteAffiliation(saveModel.mappingName);
                break;*/
        }
    }

    updateAutoEnrollmentMappings(
        mappingName,
        oldAccountRecordType,
        newAccountRecordType,
        autoProgramEnrollmentStatus,
        autoProgramEnrollmentRole
    ) {
        updateAutoEnrollmentMappings({
            mappingName: mappingName,
            oldAccountRecordType: oldAccountRecordType,
            newAccountRecordType: newAccountRecordType,
            autoProgramEnrollmentStatus: autoProgramEnrollmentStatus,
            autoProgramEnrollmentRole: autoProgramEnrollmentRole,
        })
            .then((result) => {
                this.showToast(
                    "success",
                    "Update Complete",
                    this.labelReference.editSuccessMessage.replace("{0}", result)
                );
            })

            .catch((error) => {
                // console.log('Inside error');
            });
        this.refreshAllApex();
    }

    showToast(toastType, toastTitle, toastMessage) {
        const showToastEvent = new ShowToastEvent({
            title: toastTitle,
            message: toastMessage,
            variant: toastType,
            mode: "dismissable",
        });
        this.dispatchEvent(showToastEvent);
    }
}
<|endoftext|>


<commit_before>angular
    .module("translateApp")
    .controller("EditMessageController", EditMessageController);

function EditMessageController($scope, $log, $resource) {

    // --------------
    // Initialization
    // --------------

    // --------------
    // Scope-related
    // --------------

    /* SCOPE DATA */

    $scope.messageActive = false;

    $scope.currentValue = $scope.item.target;
    $scope.savedValue = $scope.item.target; // Value saved into the server
    $scope.savingValue = $scope.item.target; // Value being saved

    $scope.status = {};
    $scope.status.saving = false; // Message is being saved (or not)
    $scope.status.error = false; // Error occurred when trying to save.

    /* SCOPE METHODS */

    $scope.onFocus = onFocus;
    $scope.onChange = onChange;
    $scope.onKey = onKey;
    $scope.isSaved = isSaved;
    $scope.shouldDisplayDetails = shouldDisplayDetails;
    $scope.suggestionSelected = suggestionSelected;
    $scope.onDetailsClose = onDetailsClose;

    /* SCOPE EVENTS */

    // Listen for focus events from our sibling directives.
    $scope.$on("edit-message-focused", onEditMessageFocused);

    $scope.$watch("messageActive", onMessageActive);

    // --------------
    // Implementations
    // --------------

    function onMessageActive(newval, oldval) {
        if(!newval && !oldval)
            return;

        if(newval && !oldval) {
            $scope.focusTextInput();
        }
    } // !onMessageActive

    /**
     * A suggestion was clicked. We should apply it and unfocus the control.
     */
    function suggestionSelected() {
        if($scope.selected == undefined || $scope.selected.suggestion == undefined)
            return;

        $log.debug("Selected suggestion: " + $scope.selected.suggestion.target);

        $scope.currentValue = $scope.selected.suggestion.target;
        // The above currentValue setting should suffice, but in this case we want it to take effect immediately
        // so that the fake onChange() call can detect it.
        $scope.setCurrentTextValue($scope.selected.suggestion.target);

        // *Disabled for now, because we are meant to focus the next item.
        // $scope.focusTextInput();

        $scope.selected.suggestion = "";

        // Trigger a fake onChange event.
        onChange();
    } // !suggestionSelected

    /**
     * Handles an edit-message-focused event, which will often be emmited
     * by our sibling directives. We hide our details page if one of our siblings has the focus.
     */
    function onEditMessageFocused(event, args) {
        $log.debug("[onEditMessageFocused]");

        var key = args.key;
        var index = args.index;

        $log.debug("Index: " + index);

        if( (key && $scope.key == key) || (index && $scope.$parent.index == index) ) {
            $scope.messageActive = true;
            $log.debug("Message active to True");

            $log.debug("WE SHOULD SELECT: " + $scope.key + " " + index);
            window.lastScope = $scope;
        }
        else {
            $log.debug("Message active to False");
            $scope.messageActive = false;
        }
    } // !onEditMessageFocused

    /**
     * True if the form is currently displaying the saved version of the text.
     */
    function isSaved() {
        return $scope.savedValue == $scope.getCurrentTextValue();
    } // !isSaved

    function onFocus(event) {

        event.preventDefault();

        $scope.messageActive = true;

        // Inform whoever may be interested (probably our sibling edit-message directives) that we have been
        // selected.
        $scope.$parent.$parent.$broadcast("edit-message-focused", {key: $scope.key});
    } // !onFocus

    function onChange() {
        $log.debug("[EditMessageController/onChange]");
        if (!isSaved()) {
            // We should query a server-side update.

            // Go to the next item; raise a go-next event.
            $log.debug("Emitting edit-go-next event");

            // If we are saving and apparently we remain the active message, we are done here, so
            // We want to automatically skip to the next.
            if($scope.messageActive) {
                $scope.$parent.$emit("edit-go-next", {index: $scope.$parent.index});
            }

            $scope.status.saving = true;
            $scope.savingValue = $scope.currentValue;

            var data = {
                "key": $scope.key,
                "value": $scope.savingValue
            };

            var UpdateMessagePut = $resource(APP_DYN_ROOT + "api/apps/bundles/:language/:target/updateMessage",
            {
                "app_url": $scope.bundle.appurl,
                "language": $scope.bundle.targetlang,
                "target": $scope.bundle.targetgroup
            }, {
                update: {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
                    }
                }
            });

            var result = UpdateMessagePut.update(data, {});

            result.$promise.then(onUpdateSuccess, onUpdateFailure);
        }

        $scope.unchangedValue = $scope.currentValue;
    } // !onChange

    function onUpdateSuccess(result) {
        $scope.status.error = false;
        $scope.status.saving = false;
        $scope.item.from_default = false; // Will no longer be from_default. We guess.
        $scope.savedValue = $scope.savingValue;
    } // !onUpdateSuccess

    function onUpdateFailure(result) {
        $scope.status.error = true;
        $scope.status.saving = false;
    } // !onUpdateFailure

    function shouldDisplayDetails(result) {
        return $scope.messageActive;
    } // !shouldDisplayDetails

    function onKey(event) {
        if (event.keyCode == 27) {
            $log.debug("Rolling back to " + $scope.unchangedValue);

            this.getModelController().$rollbackViewValue();
        }
    } // !onKey

    function onDetailsClose() {
        $scope.messageActive = false;
    } // !onDetailsClose

} // !EditMessageController<commit_msg>[translate3]: Hopefully fixed other issue<commit_after>angular
    .module("translateApp")
    .controller("EditMessageController", EditMessageController);

function EditMessageController($scope, $log, $resource) {

    // --------------
    // Initialization
    // --------------

    // --------------
    // Scope-related
    // --------------

    /* SCOPE DATA */

    $scope.messageActive = false;

    $scope.currentValue = $scope.item.target;
    $scope.savedValue = $scope.item.target; // Value saved into the server
    $scope.savingValue = $scope.item.target; // Value being saved

    $scope.status = {};
    $scope.status.saving = false; // Message is being saved (or not)
    $scope.status.error = false; // Error occurred when trying to save.

    /* SCOPE METHODS */

    $scope.onFocus = onFocus;
    $scope.onChange = onChange;
    $scope.onKey = onKey;
    $scope.isSaved = isSaved;
    $scope.shouldDisplayDetails = shouldDisplayDetails;
    $scope.suggestionSelected = suggestionSelected;
    $scope.onDetailsClose = onDetailsClose;

    /* SCOPE EVENTS */

    // Listen for focus events from our sibling directives.
    $scope.$on("edit-message-focused", onEditMessageFocused);

    $scope.$watch("messageActive", onMessageActive);

    // --------------
    // Implementations
    // --------------

    function onMessageActive(newval, oldval) {
        if(!newval && !oldval)
            return;

        if(newval && !oldval) {
            $scope.focusTextInput();
        }
    } // !onMessageActive

    /**
     * A suggestion was clicked. We should apply it and unfocus the control.
     */
    function suggestionSelected() {
        if($scope.selected == undefined || $scope.selected.suggestion == undefined)
            return;

        $log.debug("Selected suggestion: " + $scope.selected.suggestion.target);

        $scope.currentValue = $scope.selected.suggestion.target;
        // The above currentValue setting should suffice, but in this case we want it to take effect immediately
        // so that the fake onChange() call can detect it.
        $scope.setCurrentTextValue($scope.selected.suggestion.target);

        // *Disabled for now, because we are meant to focus the next item.
        // $scope.focusTextInput();

        $scope.selected.suggestion = "";

        // Trigger a fake onChange event.
        onChange();
    } // !suggestionSelected

    /**
     * Handles an edit-message-focused event, which will often be emmited
     * by our sibling directives. We hide our details page if one of our siblings has the focus.
     */
    function onEditMessageFocused(event, args) {
        $log.debug("[onEditMessageFocused]");

        var key = args.key;
        var index = args.index;

        $log.debug("Index: " + index);

        if( (key && $scope.key == key) || (index && $scope.$parent.index == index) ) {
            $scope.messageActive = true;
            $log.debug("Message active to True");

            $log.debug("WE SHOULD SELECT: " + $scope.key + " " + index);
            window.lastScope = $scope;
        }
        else {
            $log.debug("Message active to False");
            $scope.messageActive = false;
        }
    } // !onEditMessageFocused

    /**
     * True if the form is currently displaying the saved version of the text.
     */
    function isSaved() {
        return $scope.savedValue == $scope.getCurrentTextValue();
    } // !isSaved

    function onFocus(event) {

        $scope.messageActive = true;

        // Inform whoever may be interested (probably our sibling edit-message directives) that we have been
        // selected.
        $scope.$parent.$parent.$broadcast("edit-message-focused", {key: $scope.key});
    } // !onFocus

    function onChange() {
        $log.debug("[EditMessageController/onChange]");
        if (!isSaved()) {
            // We should query a server-side update.

            // Go to the next item; raise a go-next event.
            $log.debug("Emitting edit-go-next event");

            // If we are saving and apparently we remain the active message, we are done here, so
            // We want to automatically skip to the next.
            if($scope.messageActive) {
                $scope.$parent.$emit("edit-go-next", {index: $scope.$parent.index});
            }

            $scope.status.saving = true;
            $scope.savingValue = $scope.currentValue;

            var data = {
                "key": $scope.key,
                "value": $scope.savingValue
            };

            var UpdateMessagePut = $resource(APP_DYN_ROOT + "api/apps/bundles/:language/:target/updateMessage",
            {
                "app_url": $scope.bundle.appurl,
                "language": $scope.bundle.targetlang,
                "target": $scope.bundle.targetgroup
            }, {
                update: {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
                    }
                }
            });

            var result = UpdateMessagePut.update(data, {});

            result.$promise.then(onUpdateSuccess, onUpdateFailure);
        }

        $scope.unchangedValue = $scope.currentValue;
    } // !onChange

    function onUpdateSuccess(result) {
        $scope.status.error = false;
        $scope.status.saving = false;
        $scope.item.from_default = false; // Will no longer be from_default. We guess.
        $scope.savedValue = $scope.savingValue;
    } // !onUpdateSuccess

    function onUpdateFailure(result) {
        $scope.status.error = true;
        $scope.status.saving = false;
    } // !onUpdateFailure

    function shouldDisplayDetails(result) {
        return $scope.messageActive;
    } // !shouldDisplayDetails

    function onKey(event) {
        if (event.keyCode == 27) {
            $log.debug("Rolling back to " + $scope.unchangedValue);

            this.getModelController().$rollbackViewValue();
        }
    } // !onKey

    function onDetailsClose() {
        $scope.messageActive = false;
    } // !onDetailsClose

} // !EditMessageController<|endoftext|>


<commit_before>import { app, dialog, shell } from 'electron';
import GhReleases from 'electron-gh-releases';

let checking = false;

export default (mainWindow, icon, notify) => {
  if (checking) return;

  checking = true;
  const updater = new GhReleases({
    repo: 'jhen0409/react-native-debugger',
    currentVersion: app.getVersion(),
  });

  updater.check((err, status) => {
    if (
      process.platform === 'linux' &&
      err.message === 'This platform is not supported.'
    ) {
      err = null; // eslint-disable-line
      status = true; // eslint-disable-line
    }
    if (notify && err) {
      dialog.showMessageBox(mainWindow, {
        type: 'info',
        buttons: ['OK'],
        title: 'React Native Debugger',
        icon,
        message: err.message,
      });
      checking = false;
      return;
    }
    if (err || !status) return;
    if (notify) {
      const index = dialog.showMessageBox(mainWindow, {
        type: 'info',
        buttons: ['Download', 'Later'],
        title: 'React Native Debugger',
        icon,
        message: 'The new version has been released.',
      });
      if (index === 1) return;
      shell.openExternal('https://github.com/jhen0409/react-native-debugger/releases');
      checking = false;
      return;
    }
    if (process.env.NODE_ENV === 'production' && process.platform === 'darwin') {
      updater.download();
    }
  });

  updater.on('update-downloaded', ([, releaseNotes, releaseName]) => {
    const index = dialog.showMessageBox(mainWindow, {
      type: 'info',
      buttons: ['Restart', 'Later'],
      title: 'React Native Debugger',
      icon,
      message: 'The new version has been downloaded. ' +
        'Please restart the application to apply the updates.',
      detail: `${releaseName}\n\n${releaseNotes}`,
    });
    if (index === 1) {
      checking = false;
      return;
    }
    updater.install();
  });
};
<commit_msg>Add log to update.js for debug<commit_after>import { app, dialog, shell } from 'electron';
import GhReleases from 'electron-gh-releases';

let checking = false;

export default (mainWindow, icon, notify) => {
  if (checking) {
    console.log('[Updater] Already checking...');
    return;
  }

  checking = true;
  const updater = new GhReleases({
    repo: 'jhen0409/react-native-debugger',
    currentVersion: app.getVersion(),
  });

  updater.check((err, status) => {
    if (
      process.platform === 'linux' &&
      err.message === 'This platform is not supported.'
    ) {
      err = null; // eslint-disable-line
      status = true; // eslint-disable-line
    }
    if (notify && err) {
      dialog.showMessageBox(mainWindow, {
        type: 'info',
        buttons: ['OK'],
        title: 'React Native Debugger',
        icon,
        message: err.message,
      });
      checking = false;
      console.log('[Updater]', err.message);
      return;
    }
    if (err || !status) {
      console.log('[Updater] Error', err && err.message, status);
      checking = false;
      return;
    }
    if (notify) {
      const index = dialog.showMessageBox(mainWindow, {
        type: 'info',
        buttons: ['Download', 'Later'],
        title: 'React Native Debugger',
        icon,
        message: 'The new version has been released.',
      });
      if (index === 1) return;
      shell.openExternal('https://github.com/jhen0409/react-native-debugger/releases');
      checking = false;
      console.log('[Updater] Open external link.');
      return;
    }
    if (process.env.NODE_ENV === 'production' && process.platform === 'darwin') {
      updater.download();
      console.log('[Updater] Starting download...');
    }
  });
  console.log('[Updater] Checking updates...');

  updater.on('update-downloaded', ([, releaseNotes, releaseName]) => {
    console.log('[Updater] Downloaded.');
    const index = dialog.showMessageBox(mainWindow, {
      type: 'info',
      buttons: ['Restart', 'Later'],
      title: 'React Native Debugger',
      icon,
      message: 'The new version has been downloaded. ' +
        'Please restart the application to apply the updates.',
      detail: `${releaseName}\n\n${releaseNotes}`,
    });
    if (index === 1) {
      checking = false;
      return;
    }
    updater.install();
  });
};
<|endoftext|>